How Do I Give More Money To Someone With a Higher Rank?

This is my code so far:

while true do
	wait(5)
	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

In my game, I’m trying to make It so that you can buy higher ranks with cash and it will give more money every minute. This script that I made gives the player 5 cash every five seconds if they are rank zero but if you rank one it still gives you 5 cash every five seconds. Also, when you buy something the amount of cash you have goes down, but then shoots back up after 5 seconds. I’m also trying to make it so that if you’re rank one you get 10 cash instead of five. I’m not an experienced enough coder to know how to solve all of these problems so I can please have some help?

Use an if statement on the player to see what their rank is and check if it is above or below the rank you want!

Use the function Player:GetRankInGroup

its not a group rank, its a rank that you buy in game. Its like a prestige

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
            elseif v.leaderstats:FindFirstChild("Rank").Value == 1 then
                v.leaderstats["Cash"].Value = v.leaderstats["Cash"].Value + 10
			end
		end
	end
end
1 Like

Try this:

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

Oh my gosh thank you so much! I’ve been struggling for a while now. I’m very glad that you helped!

1 Like