Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to save leaderstats score between places of a Universe?

Hi, so I have a game where each level is a different place and when you complete a level, you get a certain amount of coins. I want to know how to have the same amount of Coins throughout each of the levels so I can do this. I have been looking at DataStores but it is quite confusing. Please help.

Coins Leaderboard script (with AutoSave):

local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("CoinSaveSystem")

game.Players.PlayerAdded:connect(function(player)
 local leader = Instance.new("Folder",player)
 leader.Name = "leaderstats"
 local Coins = Instance.new("IntValue",leader)
 Coins.Name = "Coins"
 Coins.Value = ds:GetAsync(player.UserId) or 0
 ds:SetAsync(player.UserId, Coins.Value)
 Coins.Changed:connect(function()
  ds:SetAsync(player.UserId, Coins.Value)
 end)
end)


game.Players.PlayerRemoving:connect(function(player)
 ds:SetAsync(player.UserId, player.leaderstats.Coins.Value)
end)

1 answer

✓ Accepted answer

A datastore is for the entire game, not for a specific place. It can be retrieved using the same method as in the start place.

2 comments

0

Oh thx very much

0

Your welcome

This discussion is preserved as it was. New answers, comments, and votes are closed.