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

How can i datastore an leaderstats stringvalue?

Asked by 4 years ago

How can i datastore an leaderstats stringvalue? i have a leaderstats script and datastore script they are different scripts leaderstats script:

01local function onPlayerJoin(player)
02    local leaderstats = Instance.new("Folder")
03    leaderstats.Name = "leaderstats"
04    leaderstats.Parent = player
05 
06    local Clicks = Instance.new("IntValue")
07    Clicks.Name = "Clicks"
08    Clicks.Value = 0
09    Clicks.Parent = leaderstats
10 
11    local Prestiges = Instance.new("IntValue")
12    Prestiges.Name = "Prestiges"
13    Prestiges.Value = 0
14    Prestiges.Parent = leaderstats
15 
View all 27 lines...

datastore script:

01local DS = game:GetService("DataStoreService"):GetDataStore("SaveMyData")
02game.Players.PlayerAdded:Connect(function(plr)
03    wait()
04    local plrkey = "id_"..plr.userId
05    local savevalue = plr.leaderstats.Clicks
06    local savevalue2 = plr.leaderstats.Prestiges
07    local savevalue3 = plr.leaderstats.Gold
08 
09    local GetSaved = DS:GetAsync(plrkey)
10    if GetSaved then
11        savevalue.Value = GetSaved[1]
12        savevalue2.Value = GetSaved[2]
13        savevalue3.Value = GetSaved[3]
14        print("Datastored")
15    else
View all 23 lines...
0
;( stevenfury91 -17 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

As far as I am aware, you cannot save a string value. What I would suggest is to have the Rank be a IntValue also, then have a separate script that loads something like

01local function onPlayerJoin(player)
02        local leaderstats = Instance.new("Folder")
03        leaderstats.Name = "leaderstats"
04        leaderstats.Parent = player
05 
06        local Clicks = Instance.new("IntValue")
07        Clicks.Name = "Clicks"
08        Clicks.Value = 0
09        Clicks.Parent = leaderstats
10 
11        local Prestiges = Instance.new("IntValue")
12        Prestiges.Name = "Prestiges"
13        Prestiges.Value = 0
14        Prestiges.Parent = leaderstats
15 
View all 32 lines...

then save the "RankSave" instead of the "Rank"

then I would use a script that runs in a playerGui (I like to do that because it can make and detect changes to server)

the script would read

01wait (2) --gives time for data to load
02 
03onchange() --this will run the script once so that it loads up one time without detecting a value change
04 
05function onchange()
06      local ranksave = script.Parent.Parent.leaderstats.RankSave
07      local rank = script.Parent.Parent.leaderstats.Rank
08      if ranksave.Value == 0 then
09      rank.Value = "Noob"
10 
11      --Continue else if for all ranks you want to have    
12 
13      end
14end
15script.Parent.Parent.leaderstats.RankSave.Changed:Connect(onchange)

then as the game goes on, change the ranksave instead of the rank and this script can change the rank string value.

I hope this helps and makes sense!

0
@DemonsEmperor where do i put the wait(2) script stevenfury91 -17 — 4y
Ad

Answer this question