How can i datastore an leaderstats stringvalue? i have a leaderstats script and datastore script they are different scripts leaderstats script:
01 | local 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 |
datastore script:
01 | local DS = game:GetService( "DataStoreService" ):GetDataStore( "SaveMyData" ) |
02 | game.Players.PlayerAdded:Connect( function (plr) |
03 | wait() |
04 | local plrkey = "id_" ..plr.userId |
05 | local savevalue = plr.leaderstats.Clicks |
06 | local savevalue 2 = plr.leaderstats.Prestiges |
07 | local savevalue 3 = plr.leaderstats.Gold |
08 |
09 | local GetSaved = DS:GetAsync(plrkey) |
10 | if GetSaved then |
11 | savevalue.Value = GetSaved [ 1 ] |
12 | savevalue 2. Value = GetSaved [ 2 ] |
13 | savevalue 3. Value = GetSaved [ 3 ] |
14 | print ( "Datastored" ) |
15 | else |
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
01 | local 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 |
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
01 | wait ( 2 ) --gives time for data to load |
02 |
03 | onchange() --this will run the script once so that it loads up one time without detecting a value change |
04 |
05 | function 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 |
14 | end |
15 | script.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!