I Need Help With Money Per Minute Script Issues

In my game, I have a system where you can buy ranks that will multiply the amount of money you make every minute. I tried coding it, so if your rank is 0, you will get 5 cash per minute. This is the script:

local leaderstats = game:GetService("Players").LocalPlayer.leaderstats

while true do
	if leaderstats.Rank.Value == 0 then
		wait(60)
		for i,v in pairs(game.Players:GetPlayers()) do
			if v:FindFirstChild("leaderstats") then
				v.leaderstats["Cash"].Value = v.leaderstats["Cash"].Value + 5
			end

		end
	end
end

I get this error message: ServerScriptService.RankMultiplier:1: attempt to index nil with ‘leaderstats’

The script works with out the line:
if leaderstats.Rank.Value == 0 then

But with that line the code does not work at all. Can someone please tell me how to fix this?

Try this:

while true do
	wait(60)
	for i,v in pairs(game.Players:GetPlayers()) do
		if v:FindFirstChild("leaderstats") then
			if v.leaderstats:FindFirstChild("Rank").Value == 0 then
				v.leaderstats["Cash"].Value = v.leaderstats["Cash"].Value + 5
			end
		end

	end
end
1 Like

This script made it work. Thanks a lot!

1 Like