Well I was making my custom leaderboard as I do, it all worked before but when I add DataStore support, it suddenly doesn't work. I don't know what the problem is and no errors occur. Here are the code chunks needed:

DataStore = game:GetService("DataStoreService"):GetDataStore("Values")

game.Players.PlayerAdded:connect(function(player)
local save = "plr-"..player.userId
local savedVals = DataStore:GetAsync(save)
   if savedVals then
        val = savedVals
   else 
        val = 0
        DataStore:SetAsync(save, val)
end
local pts = Instance.new("IntValue", player)
pts.Name = "Cash"
pts.Value = val

while wait() do
	newchatline.Text = player.Name.." - $"..pts.Value
end
end)

game.Players.PlayerRemoving:connect(function(p)
	for _,v in pairs(game.Players:GetChildren()) do
		for _,x in pairs(v.PlayerGui.Leaderboard:GetChildren()) do
			if x.Text == p.Name then
				local z = x.Name:sub(4)
				x:Destroy()
			for _,y in pairs(v.PlayerGui.Leaderboard:GetChildren()) do
				if y.Name:sub(4) > z then
					y.Position = y.Position - UDim2.new(0, 0, 0, 29)
				end
			end
			end
		end
	end
end)

game.Players.PlayerRemoving:connect(function(plr)
    local val = plr.Cash.Value
    local save = "plr-"..plr.userId
    DataStore:SetAsync(save,val)
end)

5 comments

0

What is the script supposed to do when a player removes? What you have done seems rather pointless if you can just use p.leaderstats. Also, sometimes GetAsync() does not actually get the values, try UpdateAsync() to update something.

0

p.leaderstats is non existent, as I stated, it's my own custom lederboard, I can bend it to my will, and DataStores work, it just doesn't show player's names or cash unless they were the first person in the server, sorry if I didn't make it clear.

0

@TheDeadlyPanther I can see that the first PlayerRemoving updates the leaderboard by removing the player from it and offsetting all stats below so there isn't an empty field. The UpdateAsync method is only needed if there is a possibility that the same value might be changed from different servers, which I don't see happening here.

0

@Hyphonated You shouldn't use 2 PlayerRemoving events. Also, maybe your problem isn't in this part of code. Are you really sure that your leaderboard updating script supports your new way of getting data?

0

@Hyphonated Could you explain what isn't working?