Im not sure what values to change to what.
heres the LeaderboardHandler
001 | local ds = game:GetService( "DataStoreService" ) |
002 |
003 | local PointsODS = ds:GetOrderedDataStore( "leaderstats" ) |
004 |
005 | local timeUntilReset = 10 |
006 |
007 | while wait( 1 ) do |
008 |
009 | timeUntilReset = timeUntilReset - 1 |
010 |
011 | script.Parent.Parent.Additional.ResetTimeT.Text = "Resetting In " .. timeUntilReset .. " Seconds..." |
012 |
013 | if timeUntilReset = = 0 then |
014 |
015 | timeUntilReset = 10 |
heres the savedata
01 | local DS = game:GetService( "DataStoreService" ):GetDataStore( "SaveMyData" ) |
02 | game.Players.PlayerAdded:Connect( function (player) |
03 | wait() |
04 | local playerkey = "id_" ..player.userId |
05 | local savevalue = player.leaderstats.Points |
06 | local savevalue 2 = player.leaderstats.Prestige |
07 |
08 | local GetSaved = DS:GetAsync(playerkey) |
09 | if GetSaved then |
10 | savevalue.Value = GetSaved [ 1 ] |
11 | savevalue 2. Value = GetSaved [ 2 ] |
12 | else |
13 | local NumbersForSaving = { savevalue.Value, savevalue 2. Value } |
14 | DS:GetAsync(playerkey, NumbersForSaving) |
15 | end |
16 | end ) |
17 |
18 | game.Players.PlayerRemoving:Connect( function (player) |
19 | DS:SetAsync( "id_" ..player.userId, { player.leaderstats.Points.Value, player.leaderstats.Prestige.Value } ) |
20 | end ) |
heres the leaderstats
01 | game.Players.PlayerAdded:Connect( function (player) |
02 | local leaderstats = Instance.new( "Model" ) |
03 | leaderstats.Name = "leaderstats" |
04 | leaderstats.Parent = player |
05 |
06 | local money = Instance.new( "IntValue" ) |
07 | money.Name = "Points" |
08 | money.Value = 0 |
09 | money.Parent = leaderstats |
10 | local money = Instance.new( "IntValue" ) |
11 | money.Name = ( "Prestige" ) |
12 | money.Value = 0 |
13 | money.Parent = leaderstats |
14 | local money = Instance.new( "BoolValue" ) |
15 | money.Name = "DoublePass" |
16 | money.Value = false |
17 | money.Parent = player |
18 | end ) |
This is quite simple, and honestly isn't all that hard!
First you're going to want to run a player added event obviously, and you're gonna wanna wrap it in a pcall for extra errors that get caught or incase roblox data centers go down you don't want data being lost, you just want it being caught. You're going to want to put your data stores at the top.
01 | local Ds = game:GetService( "DataStoreService" ) -- Variable name can be changed but the argument cannot. |
02 | local DataSave = Ds:GetDataStore( "NameOfDataStore" ) -- Can be anything. |
03 |
04 | game.Players.PlayerAdded:Connect( function (plr) |
05 | local leaderstats = Instance.new( "Folder" ) -- Creates a folder for it to be stored. |
06 | leaderstats.Parent = plr -- Parents it to the player |
07 | leaderstats.Name = "leaderstats" -- Sets the name of the leaderstats |
08 |
09 | local Currency = Instance.new( "IntValue" ) -- Change to any value you'd like. |
10 | Currency.Parent = leaderstats |
11 | Currency.Name = "Money" -- Put currency name here |
12 | Currency.Value = 0 -- Change to any value. |
13 | end ) |
After you do this you will do the following:
01 | local Ds = game:GetService( "DataStoreService" ) -- Variable name can be changed but the argument cannot. |
02 | local DataSave = Ds:GetDataStore( "NameOfDataStore" ) -- Can be anything. |
03 |
04 | game.Players.PlayerAdded:Connect( function (plr) |
05 | local leaderstats = Instance.new( "Folder" ) -- Creates a folder for it to be stored. |
06 | leaderstats.Parent = plr -- Parents it to the player |
07 | leaderstats.Name = "leaderstats" -- Sets the name of the leaderstats |
08 |
09 | local Currency = Instance.new( "IntValue" ) -- Change to any value you'd like. |
10 | Currency.Parent = leaderstats |
11 | Currency.Name = "Money" -- Put currency name here |
12 | Currency.Value = 0 -- Change to any value. |
13 |
14 | local Save = "Money_" ..plr.UserId -- Your data store needs a key to be identified with, so you're going to have to use a key in this case I use "Money_"..plr.UserId, you can use "Coins-" or "Coins." etc whatever the name of your currency is, is what you use. We call this later. |
15 | local data -- This can be called later aka below. |
Now onto the last step in this process.
01 | game.Players.PlayerRemoving:Connect( function (plr) -- Player is removed, it will save all the data. |
02 | local Save = "Money_" ..plr.UserId -- That key I talked about earlier? Yeah, we're picking it up again to save here! |
03 | local success, errorMsg = pcall ( function () -- Another pcall that catches errors, and keep's data. |
04 | MyData:SetAsync(Save, plr.leaderstats.Money.Value) -- We're going to SAVE the Async now, and we're saving the Players ID and also the money value because that's what is being added, you can save multiple by adding a , and doing *plr.leaderstats.Coins.Value* or *plr.leaderstats.Rebirths.Value* this will save all of it. |
05 | end ) |
06 |
07 | if success then -- If it's a success then it will print the thing below. |
08 | print ( "Saved Amazingly!" ) -- Prints this if it's a success. |
09 | else -- Another else statement, this can be used in an elseif and say elseif err then print("Error") but we do it like this so we get a clear function of what the error is! |
10 | print (errorMsg) -- Else it's going to print the error message that happened. |
11 | end |
12 | end ) |
For the leaderboard, you wanna connect it to your value that your leaderstat has and then you can display the amount they have on a text label, everything seems fine. I wrote the data store above for you just incase!