[SOLVED] "leaderstats is not a valid member of Players "Players""

Hello guys, I found another issue.

This time, the script is extremely short and quite simple to do for you guys but this is a bug unfortunately.

This is my script that has an error:

while task.wait(1) do
	game.Players.leaderstats.Money.Value += 1 -- ISSUE !!!
end

I tried to do :WaitForChild("leaderstats"); .leaderstats and both of these didn’t worked.

Video:

Sorry for the video that’s so quick.

Sorry for not having images, because If you read the title, it already says it.

But anyways, any help is appreciated.

1 Like

You’re trying to get leaderstats from Players service.
You should instead try:

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
    local leaderstats = Player:WaitForChild("leaderstats",100)
    spawn(function()
        while true do
            task.wait(1)
            leaderstats.Money.Value += 1
        end
    end)
end)
2 Likes

But… look at the script:

local Data = game:GetService("DataStoreService"):GetDataStore("THEDATAREQUIRED")

game.Players.PlayerAdded:Connect(function(plr)
	local folder = Instance.new("Folder",plr)
	folder.Name = "leaderstats"
	
	local Money = Instance.new("NumberValue", folder)
	Money.Name = "Money"
	Money.Value = 0
	
	local dataload = Data:GetAsync(tostring(plr.UserId))
	
	if dataload then
		Money.Value = dataload[1]
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	Data:SetAsync(tostring(plr.UserId),{
		game.Players:WaitForChild("leaderstats").Money.Value -- There was also an issue but due to not put "WaitForChild" because I don't know if this was an issue or not but it was and i decided to put :WaitForChild to have no errors and this worked.
	})
end)

Here again, you’re trying to get the leaderstats from the Players servcie instead of the player.
Also, you should use pcalls.

1 Like

Thank you.

Edit: I put the script on Workspace.

But this time it’s the actual script that runs the Folder and the NumberValue.