ok so i made an datastore service but it doesn't works how it is supposted to.
when i change the value in the console, it just saves it and loads after i rejoin, but when i will change the value with script, for example simple clicking script that adds + 1 to the value, it just doesn't saves value.
here is the video of what it is doing and what not -- https://youtu.be/ktCxZFdqTXk
HERE IS THE CLICK SCRIPT --:
script.Parent.MouseButton1Click:Connect(function(player)
local player = game.Players.LocalPlayer
local clicks = player:WaitForChild("leaderstats"):WaitForChild("clicks")
clicks.Value = clicks.Value +1
end)
HERE IS DATA SAVE SCRIPT--:
local ds = game:GetService("DataStoreService"):GetDataStore("SaveData")
game.Players.PlayerAdded:Connect(function(plr)
wait()
local plrkey = "id_"..plr.userId
local save1 = plr.leaderstats.clicks
local GetSaved = ds:GetAsync(plrkey)
if GetSaved then
save1.Value = GetSaved[1]
else
local NumberForSaving = {save1.Value}
ds:GetAsync(plrkey, NumberForSaving)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
ds:SetAsync("id_"..plr.userId, {plr.leaderstats.clicks.Value})
print("saved?")
end)
AND FOR THE LAST SCRIPT HERE IS LEADERSTATS SCRIPT--:
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local clicks = Instance.new("IntValue")
clicks.Name = "clicks"
clicks.Parent = leaderstats
clicks.Value = 0
end)
i have no idea what i am doing wrong, beacause i am begginer and please help me fixing that.

5 comments
Can you re-edit your question and properly put your code in a code block
Change the value of clicks on the server. The server sees it as 0 while you see it as a different value
So it does save the clicks but it has a value of 0 just simply the value of clicks in a Script instead of in a LocalScript
You can get the player by using the PlayerAdded event or with a RemoteEvent. There's a lot of methods of getting the client on the server . The developer wiki can help a lot https://developer.roblox.com/en-us/
Thank You Very Much! After Adding Remote And Changing Value With Script Instead Of LocalScript Everything Works