Having trouble with this script

Hello Developers. I am having trouble with this script. The only bit that doesn’t work is the cutscene bit and it is a server script.

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local teleportPart = script.Parent

local TELEPORT_DESTINATION = Vector3.new(78.282, 1.227, 14.722)
local TELEPORT_FACE_ANGLE = 90
local FREEZE_CHARACTER = true

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

local function teleportPlayer(otherPart)
	wait(1.5)
	local character = otherPart.Parent
	local Camera = workspace.CurrentCamera
	local Point1 = workspace.Point1

	repeat

		wait()

		Camera.CameraType = Enum.CameraType.Scriptable

	until Camera.CameraType == Enum.CameraType.Scriptable

	Camera.CFrame = Point1.CFrame
	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

teleportPart.Touched:Connect(teleportPlayer)

It is supposed to happen after the player touches the part…

local RS = game:GetService("ReplicatedStorage")
local TP = RS:WaitForChild("TeleportWithinPlace")
local TWP = require(TP)
local teleportPart = script.Parent
local Camera = workspace.CurrentCamera
local Point1 = workspace:WaitForChild("Point1")

local function teleportPlayer(otherPart)
	if otherPart.Parent:FindFirstChild("Humanoid") then
		local character = otherPart.Parent
		local humanoid = character:WaitForChild("Humanoid")
		
		repeat
			task.wait()
			Camera.CameraType = Enum.CameraType.Scriptable
		until Camera.CameraType == Enum.CameraType.Scriptable

		Camera.CFrame = Point1.CFrame

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

			local params = {
				destination = TELEPORT_DESTINATION, --these params are all being flagged as undeclared
				faceAngle = TELEPORT_FACE_ANGLE,
				freeze = FREEZE_CHARACTER
			}
			TWP.Teleport(humanoid, params)

			task.wait(1)
			humanoid:SetAttribute("Teleporting", false)
		end
	end
end

teleportPart.Touched:Connect(teleportPlayer)

I made a few slight changes like changing wait() for task.wait() and adding a check to making sure the part which causes the Touched event to fire belongs to that of a player’s character, I’ve also added a comment to the params as they are being flagged as undeclared.

1 Like

Uhm, what do I do with the params??? Remove them???

Edit: Also, when I insert your script, it doesn’t teleport me at all.

I want it to teleport and after that play cutscene.