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.
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)
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.