oof, I was trying to make a save function for my new money system regarding the leaderstats. I guess I did something wrong...again.
Current script Located in workspace
local DS = game:GetService("DataStoreService"):GetDataStore("Points") function PlayerAdded(player) local folder = Instance.new("Folder",player) folder.Name= "leaderstats" local Balance = Instance.new("IntValue",folder) Balance.Name="Balance" Balance.Value = 0 while true do wait(2.5) Balance.Value = Balance.Value + 1 DS:SetAsync(player.userId.."_DS", Balance.Value) end end game.Players.PlayerAdded:Connect(PlayerAdded)
Script before I attempted to save Located in workspace
function PlayerAdded(player) local folder = Instance.new("Folder",player) folder.Name= "leaderstats" local Balance = Instance.new("IntValue",folder) Balance.Name="Balance" Balance.Value = 0 while true do wait(2.5) Balance.Value = Balance.Value + 1 end end game.Players.PlayerAdded:Connect(PlayerAdded)
The error is, you don't have a datastore. Without it, when the player leaves, their point value will return to 0. Use it to make sure they keep their points when they rejoin. (Also make sure Enable Access to API Services is ticked)
local datastore = game:GetService("DataStoreService") local ds1 = datastore:GetDataStore("Points") game.Players.PlayerAdded:Connect(function(plr) local folder = Instance.new("Folder", plr) folder.Name = "leaderstats" local Balance = Instance.new("IntValue", folder) Balance.Name = "Balance" Balance.Value = 0 Balance.Value = ds1:GetAsync(plr.UserId) or 0 ds1:SetAsync(plr.UserId, Balance.Value) Balance.Changed:Connect(function() ds1:SetAsync(plr.UserId, Balance.Value) end) end)