Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make certain teams earn money?

Asked by 10 years ago

Hello I need help on what to do, so far I have tried to put the money earning scripts in the teams, but it doesn't work. Here is the script:

01local playerStats = {} --this keeps a list of the stats for each player that enters the game
02 
03game.Players.PlayerAdded:connect(function(player)
04    local leaderstats = Instance.new("Model", player)
05    leaderstats.Name = "leaderstats"
06game.Players.PlayerAdded:connect(function(player)
07    local leaderstats = Instance.new("Model", player)
08    leaderstats.Name = "leaderstats"
09 
10    local money = Instance.new("IntValue", leaderstats) --We instance a new IntValue as a child of 'leaderstats'
11    money.Name = "Money" --this is the name you want the leader-stat to be when it shows up in-game.
12    money.Value = 0 --this is the value of money the new player starts out with. To change this, you can add some more code (shown later)
13end)
14local money = Instance.new("IntValue", leaderstats)
15    money.Name = "Money"
View all 26 lines...

I would like an actual script for this or a solution if your answering this. Thanks.

2 answers

Log in to vote
0
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
10 years ago

Well, one way of doing it is by creating a CheckTeams function. The parameter could be the Player, or the TeamColor. Within the function, there would be an if statement, as well as elseif statements, that checks the TeamColor, and gives them the cash. Here's an example:

1function CheckTeams(player)
2    if player.TeamColor == BrickColor.new("Really red") then
3        player.leaderstats.Money.Value = player.leaderstats.Money.Value + 2
4    end
5end

All you need to do is put that into your current script, add the teams, properly add the money, and for the 'for' loop you have at the end, just have it go through the Players, not the stats.

0
Thanks for all the answers I really appreciate it, hopefully it will work now. I have accepted both answers and now you will receive reputation STICKYBUN10 19 — 10y
0
Okay so I have tried both scripts ImageLabel's one and Shawnyg's one, neither of them work sadly, I did put the teams properly and I did put both of them in workspace and ServerScriptService for tests and so far they haven't worked I still appreciate the answers and hopefully I will get this sorted for my game. Thanks anyway STICKYBUN10 19 — 10y
Ad
Log in to vote
0
Answered by
ImageLabel 1541 Moderation Voter
10 years ago
01local playerStats = {}
02local teamSalary = {
03    ["Really red"] = 200;
04    ["Purple"] = 100;
05    ["White"] = 0;
06};
07 
08local function fetchSalary (teamColor)
09    if teamColor and BrickColor.new(teamColor) then
10        for team, salary in ipairs(teamSalary) do
11            if team:upper() == teamColor:upper() then
12                return salary
13            else
14                return 0
15            end
View all 40 lines...

Put it in ServerScriptService or whatever other service will run it smoothly. You shouldn't parent it to each team.

I haven't tested it but it basically awards players a certain amount of money based on their team. In the table teamSalary, set all TeamColors and the amount you want them to receive.

the function fetchSalary iterates through the table teamSalary and returns the appropriate value based on TeamColor, or 0.

in the playerAdded event, the leaderstats are created and each player is basically assigned a slot in the playerStats table.

Finally, the while loops increments the value of Money, from the table playerStats based on the assigned value, and the presence of the player.


I have not tested the code and can't confirm that it will be 100% functional. I don't have ROBLOX Studio on my Chromebook and therefore cannot test it until I get home.

Answer this question