Team Change Teleporter

I want to achieve a script where if a player team is changed it teleports them

The issue is that is it’s not bringing out any issues at all
Tried to debug the script etc and nothing is showing up as errors.

Tried to change the moveto to cframe humanoid root part.

Devils = BrickColor.new("Bright red")
DevilPosition = game.Workspace.DevilSpawn

for i,v in pairs(game.Players:GetPlayers()) do
	print("debug 1")
	if(v.TeamColor == Devils) then
			print("debug 2")
		v.Character.HumanoidRootPart.CFrame = CFrame.new(DevilPosition)
			print("debug 3")
	end
end

Instead of changing the CFrame of the character’s HumanoidRootPart to the part itself, you will need to change it to the part’s CFrame. Try changing the HumanoidRootPart’s CFrame to DevilPosition.CFrame.

If you are running this script from the server this is the error that you should be getting:

ServerScriptService.Script:8: bad argument #1 (Vector3 expected, got Object)

The reason why you are getting this error is because you are using CFrame slightly wrong. You should change the 8th line to this to fix the error:

v.Character.HumanoidRootPart.CFrame = DevilPosition.CFrame

With your script currently it wont fire when the players team is changed. In fact if it is ran from the server it will only fire once when the game starts up and currently your script is firing before any players have even loaded in.

To create the system that you are after you should first listen for the PlayerAdded event to detect when a player has joined the game. The PlayerAdded event will return the player so you should then attach the GetPropertyChangedSignal event to the player to detect when the players team has changed:

game.Players.PlayerAdded:Connect(function(Player) -- Fires when the player joins the game
	Player:GetPropertyChangedSignal("TeamColor"):Connect(function() -- Fires when the players team changes
		if Player.TeamColor == BrickColor.new("Bright red") then
			Player.Character.HumanoidRootPart.CFrame = workspace.DevilSpawn.CFrame
		end
	end)
end)
2 Likes

Thank you! This has helped a lot and explained to me how i was using cframe wrong and how the property changed can be used. Thanks again

Maybe, for a simpler code, type this.
Of course, got it from @waterrunner.

local team = game.Teams.TEAM -- Write your team name here
game.Players.PlayerAdded:Connect(function(Player) 
  Player:GetPropertyChangedSignal("TeamColor"):Connect(function() 
	if Player.TeamColor ==  team.TeamColor then
		Player.Character.HumanoidRootPart.CFrame = workspace.DevilSpawn.CFrame
	end
end)
end)

For that way, it is way easier than using just regular BrickColor, since you could just pick the TeamColor instead. I’m completely fine with waterrunner’s script, it’s just that this script is more easier to do. I kept this simple for you. :grinning:

Thanks for that, I’ve tweaked my script now and added 2 versions for killer and survivors and added clothing and weapons etc. Thanks for all the help :slight_smile: