Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Anyone Got Any Idea How I Can Get My SaveData Script To Work With The Leaderboard Script?

Asked by
Fxicity 10
4 years ago

Im not sure what values to change to what.

heres the LeaderboardHandler

001local ds = game:GetService("DataStoreService")
002 
003local PointsODS = ds:GetOrderedDataStore("leaderstats")
004 
005local timeUntilReset = 10
006 
007while 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
View all 119 lines...

heres the savedata

01local DS = game:GetService("DataStoreService"):GetDataStore("SaveMyData")
02game.Players.PlayerAdded:Connect(function(player)
03    wait()
04    local playerkey = "id_"..player.userId
05    local savevalue = player.leaderstats.Points
06    local savevalue2 = player.leaderstats.Prestige
07 
08    local GetSaved = DS:GetAsync(playerkey)
09    if GetSaved then
10        savevalue.Value = GetSaved[1]
11        savevalue2.Value = GetSaved[2]
12    else
13        local NumbersForSaving = {savevalue.Value, savevalue2.Value}
14        DS:GetAsync(playerkey, NumbersForSaving)
15    end
16end)
17 
18game.Players.PlayerRemoving:Connect(function(player)
19    DS:SetAsync("id_"..player.userId, {player.leaderstats.Points.Value, player.leaderstats.Prestige.Value})
20end)

heres the leaderstats

01game.Players.PlayerAdded:Connect(function(player)
02     local leaderstats = Instance.new("Model")
03     leaderstats.Name = "leaderstats"
04     leaderstats.Parent = player
05 
06local money = Instance.new("IntValue")
07     money.Name = "Points"
08     money.Value = 0
09     money.Parent = leaderstats
10local money = Instance.new("IntValue")
11     money.Name = ("Prestige")
12     money.Value = 0
13     money.Parent = leaderstats 
14local money = Instance.new("BoolValue")
15     money.Name = "DoublePass"
16     money.Value = false
17     money.Parent = player
18end)
0
Please respond as this will be an update to my game Fxicity 10 — 4y
0
is this your code User#30567 0 — 4y
0
yes Fxicity 10 — 4y
0
i got the leaderboard from a tut because i had no clue how to make one Fxicity 10 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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.

01local Ds = game:GetService("DataStoreService") -- Variable name can be changed but the argument cannot.
02local DataSave = Ds:GetDataStore("NameOfDataStore") -- Can be anything.
03 
04game.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.
13end)

After you do this you will do the following:

01local Ds = game:GetService("DataStoreService") -- Variable name can be changed but the argument cannot.
02local DataSave = Ds:GetDataStore("NameOfDataStore") -- Can be anything.
03 
04game.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.
View all 31 lines...

Now onto the last step in this process.

01game.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
12end)

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!

Ad

Answer this question