I am making a game and I have a round system already made and everything. I only have one problem - I don't know how to make a reward for a whole team. A leaderstats reward, Like Gold and XP.
The real problem here is I don't know how to get all of the players on the winning team and then give them gold and XP.
The other stuff I do know how to do, Like adding the gold and XP. It's just this part that I just can't figure out.
Any help with getting all the players on a winning team would be appreciated!
I have tried doing a couple of things, But they didn't work.
Please NOTE : I do not want a whole script. I just need some help with getting the players on a team and then adding leaderstats. The adding leaderstats part is very known to me.
Unfortunately Roblox doesn't provide a property or some other method of getting everyone on a team. However, we can do it easily with a for loop:
local winnerTeamColor = BrickColor.new("Really red") for i, player in ipairs(game.Players:GetPlayers()) do if player.TeamColor == winnerTeamColor then --award end end
If you want to get the players on a certain team, you can use a for loop
to get all the players in the game and then you can use an if statement to check if the player's TeamColor
property equals a team's TeamColor property.
TeamColor is a property in the player that stores the BrickColor of the team that the player is in. ROBLOX uses this TeamColor property to determine which team you are on and places you into it. Now, let's go over how you actually get the players of the winning team.
Let's say you had the winning team stored as a variable. For this example, I've put the winning team under a suitably named variable called "winners" (TEAMNAME is the name of the team):
local winners = game.Teams.TEAMNAME
You could create a for loop that goes through each player in the game to check if they're on the winning team like so:
for i,v in pairs(game.Players:GetPlayers()) do --GetPlayers is like GetChildren, but only gets players. if v.TeamColor == winners.TeamColor then --Give player gold and XP. end end
I hope this helped you achieve what you wanted to do. Good luck with your game. :)