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.

2 comments
it is currently turned on. but it doesn't works.
i edited my description and added video about it. please check it and maybe you can find out what am i doing wrong