Here's my problem. When I'm making different values to store in a database (for example, max movement speed or max health) and I go test in ROBLOX Studio, some of the values turn 0.

For example, let's say I wrote down this:

local database = game:GetService("DataStoreService"):GetDataStore("database")

game.Players.PlayerAdded:connect(function(player)

local stats = Instance.new("Folder", player) 
stats.Name = "Stats"

local maxMovementSpeed = Instance.new("IntValue", stats)
maxMovementSpeed.Name = "Max Movement Speed"
maxMovementSpeed.Value = 32

end)

Assuming that I have written down all of the code to save the value, when I press Play, the value becomes 0. Most of the stats I create remain the same value that I originally set them to, but some of the stats' values become 0.

Also, let's say I press Play and alter a value of one of my stats. I leave, replay, and the value that I changed to remains the same, due to my script that saves the data when a player leaves. HOWEVER, when I attempt to change it back, it doesn't change back. In fact, it remains the same.

Any values that are not what I put them as I attempt to change manually during the Play session, hoping that my player leave script will save my changes. I've also tried using parts with scripts to change the values back to normal. None of this worked, and so I had to manually add in a line changing those values in my Player enters script like this:

x

maxMovementSpeed.Value = 32

end)

In this case, x is all of the code for the database. As you can see, I have to add an addition line of code to change the value to what it's SUPPOSED to be.

How can I fix this?

** Note: I've tried stating this problem as clearly and precise as I can. If there are any confusions, feel free to ask and I will try to clarify. **