Hello! I've recently been trying to script an obby game. After completing the obby, players will step on a pad that will automatically team them safe and respawn them. I'm fairly new at scripting and I haven't been able to figure out how to do it. Any and all help is appreciated (in simple terms lol)! Thank you all so much!
How to Change Team and Respawn on Touch?
3 answers
As waifu said, that site has everything you need to know about teams. But for your easiness, here's an actual script.
part = workspace.partname
part.Touched:connect(function(h)
if game.Players:GetPlayerFromCharacter(h.Parent).Team == game.Teams.Teamname then
else
game.Players:GetPlayerFromCharacter(h.Parent).Team = game.Teams.Teamname
game.Players:GetPlayerFromCharacter(h.Parent).Humanoid:TakeDamage(math.huge)
end
end)
https://wiki.roblox.com/index.php?title=Setting_Teams
This has everything you need to know about teams.
function OnTouch(Hit) local Torso = Hit.Parent:findFirstChild("Torso") if Torso ~= nil then script.Parent.BrickColor = Torso.BrickColor end end script.Parent.Touched:connect(OnTouch)
And change the brick color to what team you want them to switch to :D Also add a simple kill script like
script.Parent.Touched:connect(function(hit) if hit ~= nil then local char = hit.Parent if char ~= nil then local humanoid = char:FindFirstChild("Humanoid") if humanoid ~= nil then humanoid.Health = 0 end end end end)
This discussion is preserved as it was. New answers, comments, and votes are closed.

10 comments
Didn't test it, but hopefully it works.
should work
Sorry for another question, but is there a way to get the person to be respawned as well? Thank you so much for your help in this! :)
Oh! I completely forgot!
There! Should work now.
For some reason the script was working last night, but today it's not working. The player isn't respawning or the team isn't changing. What could be wrong? I've checked it over multiple times to make sure I didn't make an error in copying or retyping.
Any output?
09:58:36.700 - Infinite yield possible on 'Workspace.Penguin:WaitForChild("Torso")' 09:58:36.700 - Stack Begin 09:58:36.701 - Script 'Workspace.Penguin.Animate', Line 4 09:58:36.701 - Stack End 09:58:36.702 - Infinite yield possible on 'Workspace.Penguin:WaitForChild("Torso")' 09:58:36.702 - Stack Begin 09:58:36.703 - Script 'Workspace.Penguin.Movement', Line 5 09:58:36.703 - Stack End 09:58:37.98
EDIT: The teaming is working now - I made an error on my part. However, the respawn is still not working.
Hm. I could just kill the player, but that would be bad practice. Meh, I guess just killing them WOULD work.