The way I have this script set up is on death another script triggers this script to activate immediately.
local Blue = game.Teams:WaitForChild("Blue Team") local Red = game.Teams:WaitForChild("Red Team") local BlueTeleport = game.Workspace:WaitForChild("BlueSpawn").Position local RedTeleport = game.Workspace:WaitForChild("RedSpawn").Position local Players = game.Players Players.PlayerAdded:connect(function(Player) Player.CharacterAdded:connect(function(Character) local Torso = Character:WaitForChild("Torso") if Player.Team == game.Teams:WaitForChild(Blue) then Torso.CFrame = CFrame.new(BlueTeleport.X,BlueTeleport.Y+5,BlueTeleport.Z) elseif Player.Team == game.Teams:WaitForChild(Red) then Torso.CFrame = CFrame.new(RedTeleport.X,RedTeleport.Y+5,RedTeleport.Z) end end) end)
In lines 13 and 15. You already defined the team, so just do this:
if player.Team == Blue then if player.Team == Red then
Also change connect to Connect in lines 8-9. Deprecated code breaks.
Also please use DataModel:GetService( Instance className )
to get services.
So don’t do game.Teams
but do game:GetService("Teams")
.
Same for the Players
service. Not required for Workspace
though.
the reason it is giving an infinite yeild is because it detects a possible case where the instance that is being searched for may never exist, causing a pause for the script that is infinite, this is a very common warning among scripts using :WaitForChild() and is best left alone, but if it really annoys you, give a timeout
local a = script:WaitForChild("Important", 25)
basically, if the amount of time to find the instance takes longer than specified, then it will cancel the search and return nil, of course you may need it to be higher for bigger loading times, and just in case you should handle a nil if nessecary