I originally made a script where if a player from team A captures the hill, the hill turns to the team A colour, and if a player from team B captures the hill the hill turns to team B colour.
But I want to make it so that if there are 2 players from team A, the capture time halves and the points double, and if there are 3 players from team A, the points triple etc.
Likewise if there are 2 or more players from opposing teams standing on the hill, nothing happens.
I'm unsure how to script this.
The main thing I don't know how to do is how to detect whether there are more than 1 players on the hill, and how to detect there individual teams rather than just using a generic "user.TeamColor" etc.
Or is there a completely different and better way to go about all this?
Thanks.
Here's what I have:
part = game.Workspace.zone
debounce = false
function onTouch(hit)
local user = game.Players:GetPlayerFromCharacter(hit.Parent)
if not debounce then
debounce = true
if user.TeamColor == game.Teams.Mayhem.TeamColor
then
wait(1)
part.BrickColor = user.TeamColor
end
debounce = false
end
function onTouch2(hit)
local user = game.Players:GetPlayerFromCharacter(hit.Parent)
if not debounce then
debounce = true
if user.TeamColor == game.Teams.Peace.TeamColor
then
wait(1)
part.BrickColor = user.TeamColor
print(onTouch)
end
debounce = false
end
end
script.Parent.Touched:connect(onTouch)
script.Parent.Touched:connect(onTouch2)
if onTouch and onTouch2 then do
part.BrickColor = part.BrickColor.new("Yellow")
end
end
end

15 comments
do you have an idea as to how it would work
pardon me?
Like a script idea.
I'll edit what I've put in before
You are using a lot of global variables, I first recommend to switch to local.
"My idea" of how to go about it is if some1 from Team A captures hill, a separate hill variable will say "Team A". Then if some1 from Team B captures hill, it will say Team B. If 2 separate people, hill will read Team A and Team B, and then it will do something else, but this doesn't work
why is that bad that I'm using a lot of global variables?
Global variables are bad practice, because they make code messy. No mean to be rude but your code is poorly indented, and the global variables are contributing to the messy code. They also pollute the global namespace, and can increase risks for name collisions.
Also, while many people don't seem to mind, local variables are only slightly faster to access than global variables.
In my game, I used distance and detect if a player is within a radius around the part (10 studs). I store the player object inside a table and with that you can get the number of players using #table.
You'll have to detect when the player leaves the distance to remove them from the table
I used GetDistanceFromCharacter in a localscript to detect if the local player is in the radius and if they are it will fire a remote to the server so it can store the player object inside the table. And if the player is greater than the radius it fires a different remote to let the server remove the player object from the table
thank you incapaz, no offence taken lol. and thank u unsatisfie_d
A lot of typing above ^
Np, you need to add a PlayerRemoving event to because the script can break when someone is capturing and leaves