Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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)

5 comments

0

You should use SetAsync instead of UpdateAsync

0

Ok let me try,

0

Nope still doesn't work.

0

Is it because I am setting array to nil?

0

Whats in the PlayerAdded event?

1 answer

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.

2 comments

0

Where should I put httpserv:JSONDecode(DataStoreGoesHere) ?

0

Also it doesn't work. :(

This discussion is preserved as it was. New answers, comments, and votes are closed.