Need Help with ProximityPrompt to Teleport

Hi. So I was making this game and at one part, there is a door. When you press it, It teleports you to a certain position. However, it’s not working for me; here’s my script (I used CFrame):

script.Parent.Triggered:Connect(function(hit)
	local player = hit.Parent:FindFirstChild("Humanoid")
	if player then
		player.Character.HumanoidRootPart.CFrame = CFrame.new(74, 0.5, 126.25)
	end
end)

Any suggestions to fix it? Thank you very much.

the parameter “hit” is actually a player instance

1 Like

The hit argument isn’t the BasePart that trigger the prompt, that is for Touched events. The hit argument in this case is the player instance that triggered the prompt.

1 Like

Thanks for the clarification. I tried game.Players instead. Obviously that doesn’t work either.

You misread what we’ve just spoken. The hit variable is the player that triggered the prompt. You don’t have to do anything extra after that.

1 Like

Sorry. So what do I use to teleport the player?

Your code is doing right, you just have to remove the conditional statement, and refer the player variable.

1 Like
script.Parent.Triggered:Connect(function(player)
	local char = player.Character
	local rootpart = char:FindFirstChild("HumanoidRootPart")
	if rootpart then
		rootpart.CFrame = CFrame.new(74, 0.5, 126.25)
	end
end)
1 Like

Thanks for your help. The teleport script ran smoothly. I even added a protected call to make sure nothing was wrong.