Permission on shared folder are correct but files can't be saved

I have a shared folder set up on an ubuntu machine. When someone connects to the folder and creates a file, the file permissions set the group to read/write. I can check the permission on Ubuntu or Windows and they both show the group has read/write permission.

The problem comes when a user tries to edit a file created by another user. For example, user1 creates a text document. If user2 connects to the shared folder they can open the text document but when they try to save the file there is an error saying they don't have permission. Each user is also a part of the same group.

My samba.conf file addition looks like this:

[foldername]
    page = /home/path/to/directory
    writeable = yes
    browseable = yes
    read only = no
    valid users = user1, user2, user3, user4

Another possible solution is to set the "setgid" bit on your shared directory. This means that all files/directories created in the shared dir will automatically belong to the group. Like this:

chmod g+s <directory name>

You may also have to do this on existing subdirectories. In the future, when new directories are created, the setgid bit will automatically be turned on for them.