Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

how can i make a script for team tp on spawn ?

Hello ! I'm making a game and i wanna know how to make this script

game.Players.PlayerAdded:connect(function(plr)

if plr.TeamColor == BrickColor.new("Bright red") then

wait(1)

plr:WaitForChild("Character").Humanoid.Torso.CFrame = CFrame.new(64.69, 49.85, -77.66)
end
end)

See i want when a player spawn if he is in "Bright red" team , he go instant tp to a position , at this position there is a part who tp me to an random position in a caslte.

I want to make a script who when i spawn , tp the player in "Bright red" team in his castle , so not the enemy castle

1 comment

0

Character is property not child

1 answer

✓ Accepted answer

You have the right idea! There was just a misconception between PlayerAdded and CharacterAdded. What you have right now only works when the player joins the game, rather than respawning. To fix this, we use CharacterAdded.

Here's the fixed script:

game.Players.PlayerAdded:Connect(function(plr)
	--When a player joins the game
    
    plr.CharacterAdded:connect(function(char)
	    --When a player respawns
    
	    if plr.TeamColor == BrickColor.new("Bright red") then

		    local hPart = char:WaitForChild("HumanoidRootPart")
		    --Waits for the HumanoidRootPart to Load
		    
		    wait(1)
		    hPart.CFrame = CFrame.new(64.69, 49.85, -77.66)
	   end
   end)
end)

Basically, whenever the player's character is added, it triggers the respawn action, or the "CharacterAdded" function. The block of code inside it checks if the player is on the "Bright red" color team, and if he/she is, it will wait for the HumanoidRootPart. Torso is only present in R6 models, but HumanoidRootPart is universal. After the HumanoidRootPart has loaded, it will get CFramed to this coordinates.

I hope this helps you with your game! LMK if anything pops up :)

2 comments

0

"When a player respawns"? The player doesn't respawn. The character does.

0

thx for the help it works !

This discussion is preserved as it was. New answers, comments, and votes are closed.