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

How to keep track of players leaderstats?

Ok so i made a leaderstats cash and the leaderstats is working correct but i want to take a track of the cash and when someone reaches 500,000 then it will print has alot of cash but it dosen't work here is the script i used:

game.Players.PlayerAdded:Connect(function(plr)
	if plr.leaderstats.Cash.Value == 500000 then
		print("has alot of cash")
	end
end)

if your wondering if my leaderstats script is correct and working then i want to tell you it works and i tested it and the following script is on server script service

2 comments

0

where are you changing the stats/how

0

try >= instead of ==

2 answers

Try this:

game.Players.PlayerAdded:Connect(function(player)
	local cash = player:WaitForChild("leaderstats"):WaitForChild("Cash")
	cash.Changed:Connect(function()
		if cash.Value >= 500000 then
			print(player.Name.." has a lot of cash")
		end
	end)
end)

Hello kind sir! I have just the thing!

game.Players.PlayerAdded:Connect(function(player)
    local cash = player:WaitForChild("leaderstats"):WaitForChild("Cash")--Finds the players cash
    if cash then--If the cash exists in the player then
	cash.Changed:Connect(function()--This runs every time the cash changes
        	if cash.Value >= 500000 then--If the players cash is large then do something
            		print(player.Name.." has a lot of cash")
			--Your code here!
        	end
    end)
    end
end)

This is simply a modification to the answer above. The Changed function detects whenever a value changes, so you can also use this for players in the server and stuff. I hope this helps you in your scripting journey! If you have any questions or concerns, comment below!

Best,

TheLastHabanero

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