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

How do I add a data store to a leaderboard I made previously?

Asked by 7 years ago

I am trying to add a data store to my leaderstats so the amount of points and survivals a player makes is saved so that when they join again they have the same number of points and wins as I have a shop GUI where you can buy stuff using the points. In addition, I want the players to have the gear they buy in the game to be with them when they join.

I tried to make a datastore on a separate script in the workspace but when I join my game a leaderboard comes up but it isn't the leaderboard I made previously as a player isn't receiving points when they survive on the new leaderboard.How do I make a datastore for my existing leaderboard?

This is the code for my leaderboard:

001bin = script.Parent
002 
003 
004 
005---------- For Announcing Who Survived
006feedbackEnabled = true
007function feedback(parent, message)
008    if not feedbackEnabled then return end
009    local h = parent:findFirstChild("announcement")
010    if h ~= nil then
011        h.Text = message
012    else
013        h = Instance.new("Message")
014        h.Name = "announcement"
015        h.Text = message
View all 169 lines...

`

This is the code for my datastore:

01local datastore = game:GetService("DataStoreService"):GetDataStore("GameStore") --Call "GameStore" whatever you like
02 
03 
04game.Players.PlayerAdded:connect(function(player)
05    local leaderstats = Instance.new("IntValue")
06    leaderstats.Name = "leaderstats"
07    leaderstats.Parent = player
08 
09    local points = Instance.new("IntValue")
10    points.Name = "Points"
11    points.Parent = leaderstats
12 
13    local survivals = Instance.new("IntValue")
14    survivals.Name = "Survivals"
15    survivals.Parent = leaderstats
View all 34 lines...

Thank You and help would be appreciated

1 answer

Log in to vote
0
Answered by 7 years ago

In your leaderboard script you create the leaderboard, and you also create the same values in the data-store script. Create the leaderboard values in one of the scripts so, it doesn't create two of each value. Just add--

1leaderstats = player:WaitForChild("leaderstats")
2leaderstats:WaitForChild("Survivals")
3leaderstats:WaitForChild("Points")

--in the script that doesn't create the leaderboard values so it doesn't fire its operations before the leaderstats are loaded.

0
I dont know how to add the script you showed. Can you please post the datastore script with the new leaderboard values Thankk You aspiringstar346 8 — 7y
Ad

Answer this question