While attempting to make a leaderboard script that automatically adds a certain amount of currency to a player every minute based off of their rank, I've run into a problem. While the leaderboard properly displays the users' rank, there's no value labeled "Gold". Script below, thank you for any help!
game.Players.PlayerAdded:connect(function(player)
leaderstats = Instance.new("IntValue")
leaderstats.Name = "leaderstats"
leaderstats.Value = 0
gold = Instance.new("IntValue")
gold.Name = "Gold"
gold.Value = 0
rank = Instance.new("StringValue")
rank.Name = "Rank"
rank.Value = player:GetRoleInGroup(3026186)
leaderstats.Parent = player
rank.Parent = leaderstats
local function getGold(plyr,rank)
p = game.Players:WaitForChild(plyr)
Gold = p.leaderstats.Gold.Value
if rank == "[C] Peasant" then
Gold = Gold + 2
elseif rank == "[C] Merchant" then
Gold = Gold + 15
elseif rank == "[C] Shopkeeper" then
Gold = Gold + 20
elseif rank == "[C] Wealth Nobleman/Noblewoman" then
Gold = Gold + 50
elseif rank == "[M] Enlisted" then
Gold = Gold.Value + 5
elseif rank == "[M] Private" then
Gold = Gold + 10
elseif rank == "[M] Corporal" then
Gold = Gold + 20
elseif rank == "[M] First Sergeant" then
Gold = Gold + 20
elseif rank == "[M] Staff Officer" then
Gold = Gold + 200
elseif rank == "[M] 2nd Lieutenant" then
Gold = Gold + 30
elseif rank == "[M] 1st Lieutenant" then
Gold = Gold + 30
elseif rank == "[M] Captain" then
Gold = Gold + 35
elseif rank == "[M] Field Marshal" then
Gold = Gold + 35
elseif rank == "[M] High Constable" then
Gold = Gold + 40
elseif rank == "[N] Knight" then
Gold = Gold + 45
elseif rank == "[N] Baron/Baroness" then
Gold = Gold + 45
elseif rank == "[N] Count/Countess" then
Gold = Gold + 60
elseif rank == "[N] Duke/Duchess" then
Gold = Gold + 70
elseif rank == "[N] King" then
Gold = Gold + 100
end
end
while true do
wait(60)
getGold(player,rank.Value)
end
end)

2 comments
Thank you! I'll incorporate table, not sure why I hadn't thought of that. If I wanted the function to be run at the same time for all players/globally, would I just move it to outside of the PlayerAdded function?
I'le add an example