Proximity Prompt Teleport Script Not Initiating

So I have used the Teleport Module and Teleport on Part Touch script from Teleporting Within a Place but changed it slightly to work with a proximity prompt. I’ve kept the Teleport Module the same but I’ve edited the Teleport on Part Touch script to this:

Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local proximityPrompt = script.Parent.ProximityPrompt

local TELEPORT_DESTINATION = Vector3.new(50, 0, 50)
local TELEPORT_FACE_ANGLE = 0
local FREEZE_CHARACTER = true

-- Require teleport module
local TeleportWithinPlace = require(ReplicatedStorage:WaitForChild("TeleportWithinPlace"))

local function teleportPlayer(otherPart)
	local character = otherPart.Parent
	local humanoid = character:FindFirstChild("Humanoid")

	if humanoid and not humanoid:GetAttribute("Teleporting") then
		humanoid:SetAttribute("Teleporting", true)

		local params = {
			destination = TELEPORT_DESTINATION,
			faceAngle = TELEPORT_FACE_ANGLE,
			freeze = FREEZE_CHARACTER
		}
		TeleportWithinPlace.Teleport(humanoid, params)

		wait(1)
		humanoid:SetAttribute("Teleporting", nil)
	end
end

proximityPrompt.Triggered:Connect(teleportPlayer)

It used to work when I touched the part but now that I’ve switched it to a proximity prompt it doesn’t do anything when I trigger it. Does anyone know the fix?

2 Likes

The issue I see is that proximityPrompt.Triggered event does not pass the same parameters as the part.Touched event. You’re still expecting a part to be passed, but the proximity prompt passes the player object that triggered the prompt.

I think the only thing that needs changed is the character variable.

Here’s the updated code:

local function teleportPlayer(player)
	local character = player.Character
	local humanoid = character:FindFirstChild("Humanoid")

	if humanoid and not humanoid:GetAttribute("Teleporting") then
		humanoid:SetAttribute("Teleporting", true)

		local params = {
			destination = TELEPORT_DESTINATION,
			faceAngle = TELEPORT_FACE_ANGLE,
			freeze = FREEZE_CHARACTER
		}
		TeleportWithinPlace.Teleport(humanoid, params)

		wait(1)
		humanoid:SetAttribute("Teleporting", nil)
	end
end

Hope this helps!

1 Like