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.