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

Points get blanked off when player rejoins same Server? (DataStoreHelp)

Asked by 6 years ago

I have a Points Leaderboard in our Cafe Game. It works fine. But when someone leaves and rejoins the Same server their Points get blanked. If they join another server it doesn't happen. Here is the script of when they leave -

game.Players.PlayerRemoving:connect(function(player)
    if array[player.Name] ~= nil then
        game:GetService("DataStoreService"):GetDataStore("Points"):UpdateAsync("user_"..player.userId, function(oldValue)
            local newValue = array[player.Name]
            return newValue
        end)
        array[player.Name] = nil

    end
end)
0
You should use SetAsync instead of UpdateAsync gmatchOnRoblox 103 — 6y
0
Ok let me try, halfvedantpandya1234 6 — 6y
0
Nope still doesn't work. halfvedantpandya1234 6 — 6y
0
Is it because I am setting array to nil? halfvedantpandya1234 6 — 6y
0
Whats in the PlayerAdded event? Dog2puppy 168 — 6y

1 answer

Log in to vote
0
Answered by
Aimarekin 345 Moderation Voter
6 years ago
local httpserv = game:GetService("HttpService")
game.Players.PlayerRemoving:connect(function(player)
    if array[player.Name] ~= nil then
        game:GetService("DataStoreService"):GetDataStore("Points"):SetAsync("user_"..player.userId, httpserv:JSONEncode(array[player.Name])

Try this. What I am doing is encoding the array so that it has a proper format when sending it to the web. I am encoding it into JSON so that it can be sent. Remember to use

httpserv:JSONDecode(DataStoreGoesHere)

to make it back an array, otherwise you'll get a string!

Not sure if it will work, try it.

And remember you must be on a live game. Studio does not save data stores.

0
Where should I put httpserv:JSONDecode(DataStoreGoesHere) ? halfvedantpandya1234 6 — 6y
0
Also it doesn't work. :( halfvedantpandya1234 6 — 6y
Ad

Answer this question