How to add cash to all members of a team?
I'm using the default Roblox CTF script (which could be found in the CTF Template), and I made an IntValue
in leaderstats
called Cash
. I found out how to add cash to the player who succesfully captured the flag, but I want to be able to add cash to all the players of the team who scored a point. The part where the script adds the point is on lines 116 - 120.
Here's the script:
001 | local TeamManager = { } |
004 | local Teams = game.Teams |
005 | local Players = game.Players |
008 | local Configurations = require(game.ServerStorage.Configurations) |
009 | local DisplayManager = require(script.Parent.DisplayManager) |
013 | local TeamPlayers = { } |
018 | for _, team in ipairs (Teams:GetTeams()) do |
019 | TeamPlayers [ team ] = { } |
025 | local function GetTeamFromColor(teamColor) |
026 | for _, team in ipairs (Teams:GetTeams()) do |
027 | if team.TeamColor = = teamColor then |
036 | function TeamManager:ClearTeamScores() |
037 | for _, team in ipairs (Teams:GetTeams()) do |
039 | DisplayManager:UpdateScore(team, 0 ) |
043 | function TeamManager:HasTeamWon() |
044 | for _, team in ipairs (Teams:GetTeams()) do |
045 | if TeamScores [ team ] > = Configurations.CAPS_TO_WIN then |
052 | function TeamManager:GetWinningTeam() |
053 | local highestScore = 0 |
054 | local winningTeam = nil |
055 | for _, team in ipairs (Teams:GetTeams()) do |
056 | if TeamScores [ team ] > highestScore then |
057 | highestScore = TeamScores [ team ] |
064 | function TeamManager:AreTeamsTied() |
065 | local teams = Teams:GetTeams() |
066 | local highestScore = 0 |
068 | for _, team in ipairs (teams) do |
069 | if TeamScores [ team ] = = highestScore then |
071 | elseif TeamScores [ team ] > highestScore then |
073 | highestScore = TeamScores [ team ] |
079 | function TeamManager:AssignPlayerToTeam(player) |
081 | local lowestCount = math.huge |
082 | for team, playerList in pairs (TeamPlayers) do |
083 | if #playerList < lowestCount then |
085 | lowestCount = #playerList |
088 | table.insert(TeamPlayers [ smallestTeam ] , player) |
089 | player.Neutral = false |
090 | player.TeamColor = smallestTeam.TeamColor |
093 | function TeamManager:RemovePlayer(player) |
094 | local team = GetTeamFromColor(player.TeamColor) |
095 | local teamTable = TeamPlayers [ team ] |
096 | for i = 1 , #teamTable do |
097 | if teamTable [ i ] = = player then |
098 | table.remove(teamTable, i) |
104 | function TeamManager:ShuffleTeams() |
105 | for _, team in ipairs (Teams:GetTeams()) do |
106 | TeamPlayers [ team ] = { } |
108 | local players = Players:GetPlayers() |
109 | while #players > 0 do |
110 | local rIndex = math.random( 1 , #players) |
111 | local player = table.remove(players, rIndex) |
112 | TeamManager:AssignPlayerToTeam(player) |
116 | function TeamManager:AddTeamScore(teamColor, score) |
117 | local team = GetTeamFromColor(teamColor) |
118 | TeamScores [ team ] = TeamScores [ team ] + score |
119 | DisplayManager:UpdateScore(team, TeamScores [ team ] ) |
If you are on the template, you can find this script in: game.ServerScriptService.MainGameScript.GameManager.TeamManager