Teleport Pad Script Not Working

Hey, I’m trying to create a teleporting script that makes it when you touch pad1 it teleports you to pad2. Can someone please help me with what I’m doing wrong? The script is located inside of pad1.

local pad1 = script.Parent
local pad2 = workspace.Pads.Pad2

pad1.Touched:Connect(function()
	local Humanoid = workspace:FindFirstChild("Humanoid")
	if Humanoid then
		local HRP = Humanoid.Parent:FindFirstChild("HumanoidRootPart")
		if HRP then
			HRP.CFrame = CFrame.new(pad2.Position)
		else
			print("HRP wasnt found")
		end
	end
end)

I’m getting this error in the console

Use the following code, if the script loads before Pad2 then Pad2 is invalid, so instead you have to wait for it.

local pad2 = workspace:WaitForChild("Pads"):WaitForChild("Pad2")

It will give an warning if it’s unable to find Pad2.

You are also looking for the humanoid in the workspace. It will be under the player’s Character.

pad1.Touched:Connect(function(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    if humanoid then
        print("Humanoid found")
    end
end)

Did all of that code, this is what it looks like now

local pad2 = script.Parent
local pad1 = workspace:WaitForChild("Pads"):WaitForChild("pad1")

pad2.Touched:Connect(function(hit)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	if humanoid then
		local humanoid = humanoid.Parent:FindFirstChild("Humanoid") 
		humanoid.CFrame = CFrame.new(pad1.Position)
	else
		print("Humanoid wasnt found")
	end
end)

This is the new error I get

Humanoids do not have CFrames, instead you should do:

hit.Parent:PivotTo(CFrame.new(pad1.Position))

PivotTo is used to change the CFrame of the whole model

More Info:
:PivotTo

Here Is My Script

script.Parent.Touched:Connect(function(hit)
	hit.Parent:FindFirstChild("HumanoidRootPart").CFrame = workspace.part2.CFrame + Vector3.new(0,5,0) --part2 is your secondpart and vector3 plus is made for not get stucked by a second part. You Don't Have To Use PivotTo.
end)

If You Find No Error Mark It As A Solution

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.