Im pretty new to Scripting. And i have an idea for a game like tag, when someone gets hit or goes close to another person theyre the ones whos on and it likes a loop. However, ive looked around and i have tried most things to try and script this game but i cant. Would you use teams for making this sort of gamemode or something else. If theyre is a script out there that is able to change a persons team when touched by another person that would be very useful :)
COMMUNITY QUESTION
is there a way to make a tag gamemode, when a player touches another player they swap teams?.
1 answer
yes there is, you can listen for when the any of the player's limbs are touched, then verify if the other touching part is a player's limb, if so then get their teams and swap em.. like this
local Players = game.Players
Players.PlayerAdded:Connect(function(player)
local character = player.Character or player.CharacterAdded:Wait();
local humanoid = character:WaitForChild("Humanoid");
humanoid.Touched:Connect(onLimbTouched)
end)
function onLimbTouched(other_limb, player_limb)
local this_player = Players:GetPlayerFromCharacter(player_limb.Parent)
local other_player = Players:GetPlayerFromCharacter(other_limb.Parent);
if(other_player) then
local other_color = other_player.TeamColor
other_player.TeamColor = this_player.TeamColor
this_player.TeamColor = other_color
end
end
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
If say someone was the one that was on theyre on a different team to everyone else who are on the "running team" when the person who is on touches someone from the running team, the person from the running team becomes on.
I would not use teams, look into Object Oriented Programming for this.
how would that help?