01 | game.Players.ChildRemoved:Connect( function (plr) |
02 | dsservice = game:GetService( "DataStoreService" ) |
03 | datastore = dsservice:GetDataStore( "Rank" ) |
04 | datastore:SetAsync(plr.UserId, plr.Rank.Value) |
05 | end ) |
06 |
07 | game.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 |
12 | end ) |
I Am Trying To Save A Rank But After some Tests It Doesn't Save The Rank And I Don't Know Why
Try this
01 | local datastore = game:GetService( "DataStoreService" ) |
02 | local rankdatastore = datastore:GetDataStore( "Rank" ) |
03 |
04 | game.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) |
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