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

Why is my script not teleporting a player?

local Part = game.Workspace.GohxiongArmyWarehouse:FindFirstChild("TP")
local Player = game.StarterPlayer.StarterCharacter:FindFirstChild("HumanoidRootPart")

Part.Touched:Connect(function()
Player.CFrame = CFrame.new(Vector3.new(0, 50, 0))
end)

This is to tp a player to 0,50,0 but it doesnt work. Please help.

1 comment

0

you cant access the player through starterplayer, you do it through the players service

2 answers

✓ Accepted answer
local Part = game.Workspace.GohxiongArmyWarehouse:FindFirstChild("TP")
local Player = game.Players[playerYouWantToFind]
local char = Player.Character or Player.CharacterAdded:Wait() --//Will wait for their character if it's not added.

game.Part.Touched:Connect(function()
	char:FindFirstChild("HumanoidRootPart").Position = Vector3.new(0,50,0)
end)

You can't use CFrame if it is a Vector3 value because CFrame is not a Vector3 value. It has 9 digits. So you must use position. Also you need to use the Players service in the game to get a player. You can't get them from StarterPlayer

You can use :SetPrimaryPartCFrame() and game.Players:GetPlayerFromCharacter(). I also added a debounce.

local Part = game.Workspace.GohxiongArmyWarehouse:FindFirstChild("TP")
local debounce = false

Part.Touched:Connect(function(hit)
if debounce == false then
debounce = true
game.Players:GetPlayerFromCharacter(hit.Parent):SetPrimaryPartCFrame(CFrame.new(0, 50, 0))
end
end)

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