E to teleport script

Hi im making a teleport thing while you hold E and it teleports you. I was wondering how to make it actualy teleport. Im using Proximity Prompts. if possible I need to know how to make text pop up saying teleport, just the fire event.

local ProximityPromptService = game:GetService("ProximityPromptService")

local function onPromptTriggered(promptObject, player)
	player.Parent:MoveTo(Vector3.new(-333.16, -1.43, 6.83))
	wait(0.4)
end
ProximityPromptService.PromptTriggered:Connect(onPromptTriggered)

https://gyazo.com/33cde5f1655e3f8d13cd9a3d4d548d6b

doesnt work

1 Like

Not sure why you are trying to get two parameters out of an event that only returns one. Always reference API documentation since it can clear up a lot of things.

And note, this returns the Player instance, not the Character instance.

1 Like

ok well i really know nothing you said because im new to the teleport thing.

1 Like

Sorry, I made a mistake in my previous reply. I glanced over that you were using ProximityService instead of the ProximityPrompt.

But the same still applies with your “player” parameter (The value that the function is using). If you want to move the player you have to get it’s character. By doing player.Character and then finding the Humanoid in the player’s Character.

1 Like

local ProximityPromptService = game:GetService(“ProximityPromptService”)

local function onPromptTriggered(promptObject, player)

player.Parent:MoveTo(Vector3.new(-333.16, -1.43, 6.83))

wait(0.4)

end

1 Like

They’re using ProximityPromptService, so the PromptTriggered event does in fact return two parameters.

Edit: Didn’t see that you made another reply. My apologies!

3 Likes

So what do I do?
to make this work

1 Like

You need to define the right Instance to call the MoveTo function on. (Humanoid will make the player walk to the location). If you want to make the player teleport I would advice not using MoveTo and instead opting to change the CFrame of the HumanoidRootPart.

local ProximityPromptService = game:GetService("ProximityPromptService")

local function onPromptTriggered(promptObject, player)
    if player.Character then
        player.Character.Humanoid:MoveTo(Vector3.new(-333.16, -1.43, 6.83))
    end
end

ProximityPromptService.PromptTriggered:Connect(onPromptTriggered)
2 Likes

As you already know, PromptTriggered returns a player parameter. However, the parent of any player is “Players”. You would need to use player.Character if you are trying to refer to the player’s character.

local ProximityPromptService = game:GetService(“ProximityPromptService”)

local function onPromptTriggered(promptObject, player)

player.Character.HumanoidRootPart.Position = Vector3.new(-333.16, -1.43, 6.83)

wait(0.4)

end

I used player.Character.HumanoidRootPart.Position because Models don’t directly have a “Position” property. Doing player.Character.Humanoid:MoveTo(Vector3.new(-333.16, -1.43, 6.83)) would also work. You can ALSO use Model:SetPrimaryPartCFrame as an alternative to HumanoidRootPart.Position.

1 Like

Is not working, no errors… can you help

@xZylter 's script should be working, but as said in my other reply, there are a number of alternatives such as:

player.Character:SetPrimaryPartCFrame()
player.Character.HumanoidRootPart.Position = Vector3.new()
--and more

Try integrating one of these.

his script doesnt work either. im trying all but im just a noob lmao

Hey @jackthehunter25! I was just trying to create the same sort of deal, implementing doors that will teleport you to the other side upon triggering a proximity prompt for my game!

I happened to find this tutorial; I hope it helps you as it has helped me.

2 Likes

The problem is, that your LocalScript seems to be in the workspace… LocalScripts don’t work in the workspace, i think…