My IntValue not saving

I see you are using a localscript to change the value, that won’t work. You need to change the value server-sided, otherwise the Datastore won’t detect a change in the value and won’t save it.

it doesn’t work idk… :smiley:

You don’t need userid you just need player, value

i want to save gui money not leaderstats

You need the UserId, so the keys are unique to each player. Instances can not be a key.

Just use leaderstats and make the gui say the value of Cash??

You might’ve missed an equals sign when you pcall, try checking that.

My point is you can’t save anything locally. It needs to be SERVER-SIDED. So you need to make a value for the player and save/change it from there.

can you show me example if no its ok

Wait my DataStore works and I dont use UserId? please explain this

Take a look at this article on Datastores for some information. You can also find videos online for help.

Is the script that you sent a screenshot of a Script and not a LocalScript?

its Server Script and it located in the server script service

I think it is an issue with Roblox Studio. Sometimes when the player leaves inside of Studio, the Players.PlayerRemoving event doesn’t function properly. Try adding an autosave system.

idk how to make auto save one xD you have one?

Just insert this:

coroutine.resume(coroutine.create(function()
while wait(60) do
for _, player in ipairs(game.Players:GetPlayers()) do
onPlayerExit(player) -- call your save function which is this one
end
end
end))

still not saving :frowning: idk what to do

First of all, changing a value on the client from a LocalScript will not change the value on the server. If you’re using a LocalScript to change the value (which is a really bad idea from a security point of view), it’ll still be 0 as far as the server is concerned.

However, if the value is being changed by a server script, is your data being loaded successfully? If so, your test session might just be disconnecting before it actually prints, so you’ll never see this unless you start a test server or try it in game with two players.

Also, if the IntValue is being created client-side, it won’t exist as far as the server is concerned.

You’re actually better off (and more secure) storing data in a table on the server, and having a server script save the data inside the table. If the client needs to make a change to the data, it should fire a RemoteEvent to request a change and the server should verify if they’re allowed to do it.

2 Likes

Can you try something? Before being kicked change your cash, then click above on CLIENT, it will switch to server, and then check if the cash thing is right.

This isn’t a good pratice, because if the game happens to shut down, and the player leaves, and there is no running code to save the data, the data will be lost. So, instead, you can just make an autosave loop that saves every x amount of time.