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

How would imake a job's salary/wages?

I am in the process of creating a city based game and I am not sure how to make it so if you are a certain TeamColor then you get a certain amount of money. I have tried editing the Leaderboard's artice on the wiki's script.

game.Players.PlayerAdded:connect(function(player)
    local leaderstats = Instance.new("Model")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player
    local money = Instance.new("IntValue")
    money.Name = "Money"
    money.Value = 0
    money.Parent = leaderstats
end)
 if game.Players.LocalPlayer.TeamColor = "Pearl"
while wait(5) do 
    for _, player in ipairs(game.Players:GetPlayers()) do
        if player:FindFirstChild("leaderstats") then
            player.leaderstats.Money.Value = player.leaderstats.Money.Value + 1
        end
    end
end

I am sorry if the code does not work I am not sure how to do the code snippets so if you could tell me how if this is wrong then please! :)

2 comments

0

I just put in " if game.Players.LocalPlayer.TeamColor = "Pearl" on line 10

0

Edited for code block.

1 answer

Working code example :

game.Players.PlayerAdded:connect(function(player)
    local leaderstats = Instance.new("Model")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player
    local money = Instance.new("IntValue")
    money.Name = "Money"
    money.Value = 0
    money.Parent = leaderstats
end)

teamsIncome={Pearl=5,['Bright red']=3,White=1}

while wait(5) do 
    for _, player in pairs(game.Players:GetPlayers()) do
        if player:FindFirstChild("leaderstats") then
			local team=tostring(game.Players.LocalPlayer.TeamColor)
			local income=teamsIncome[team]
			if income==nil then
				print('No income set up for team '..team)
			else
				player.leaderstats.Money.Value = player.leaderstats.Money.Value + income
			end
        end
    end
end

What I did was simply associate each team color to an income value in a table teamsIncome, then every 5 secs we loop through each player and increase his/her money by the amount corresponding to his team in the table.

I added an exception for the case when you have a player whose team doesn't have a configured income just in case.

Feel free to comment if you have questions on the answer, I'll edit it accordingly

1 comment

0

Thank you! It works very well.

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