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

Saving String Value Not Working?

Asked by 4 years ago
01game.Players.ChildRemoved:Connect(function(plr)
02    dsservice = game:GetService("DataStoreService")
03    datastore = dsservice:GetDataStore("Rank")
04    datastore:SetAsync(plr.UserId, plr.Rank.Value)
05end)
06 
07game.Players.ChildAdded:Connect(function()
08    dsservice = game:GetService("DataStoreService")
09    datastore = dsservice:GetDataStore("Rank")
10    local text = datastore:GetAsync("Rank")
11    script.Parent.Rank.Value = text
12end)

I Am Trying To Save A Rank But After some Tests It Doesn't Save The Rank And I Don't Know Why

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Try this

01local datastore = game:GetService("DataStoreService")
02local rankdatastore = datastore:GetDataStore("Rank")
03 
04game.Players.ChildAdded:Connect(function(plr)
05 
06    local data
07    local success, errormessage = pcall(function()
08        data = rankdatastore:GetAsync(plr.UserId.."-rank")
09    end)
10 
11    if success then
12        -- here change the rank value, for example Rank.Value = data
13     else
14        print("There was an error whilst getting your data")
15        warn(errormessage)
View all 30 lines...
Ad
Log in to vote
0
Answered by
MemezyDev 172
4 years ago

it isnt working because you’re not specifying what youre getting, you are just getting ‘Rank’ but you save a value

GetAsync cant have 2 args, at least that works for me. the only arg there is the code, in which case is the players userid, what i do is attach a string to the players userid by doing datastore:GetAsync(player.UserId.. ‘-rank’) which will be able to be seperated from different players, and also be able to grab the right value. also you should wrap the :GetAsync() in a pcall function so it doesnt error incase the :GetAsync() fails. if this helped please accept my answer, else i will be happy to help you in the community chat

Answer this question