Help with data stores

im currently making like a minigame type game and i have a leaderstat called wins, I’m trying to make the wins save after you leave with data stores but every tutorial or script i find is outdated and doesn’t work, if anyone could give me a working tutorial or script for data stores it would be much appreciated

1 Like

Maybe show us your script you have rn.

i dont have one, i have tryed many by following tutorials but none work even though i copy them word for word, im just asking if anyone knows a good tutorial or script that works that they could send me

Watch this tutorial since this one works

3 Likes

I would save the wins in leaderstats Link.
When a player is joining the game you read from the DataStore Link and see if any wins have been saved for that player already. If not you’ll skip that part and set your wins in the leaderstats to 0.
Every win they get is saved to the leaderstats and written to the datastore. Alternatively you can write it to the datastore once the player leaves.

Yeah ive done all of that but everything in my game keeps resetting for example, My overhead random number generated ui and my currency even tho its followed the documentation for datastores and worked before and all of a sudden it stopped working i am not sure why, It is weird

make a server script in “ServerScriptService” and inside add this:

–name the script leaderstats
local dataSaving = game:GetService(“DataStoreService”)
local winsSave = dataSaving:GetDatastore(“WinsSave”)

game.Players.PlayerAdded:Connect(function(plr)
local stats = Instance.new(“Folder”)
stats.Name = “leaderstats”
stats.Parent = plr
local wins = Instance.new(“IntValue”)
wins .Name = “wins”
wins .Parent = stats
wins.Value = winsSave:GetAsync(plr.UserId) or 0
print(“Got Wins”)
end)

game.Players.PlayerRemoving:Connect(function(plr)
local wins = plr.leaderstats.wins
winsSave:SetAsync(plr.UserId, wins.Value)
print(“Saved Wins”)
end)