I am trying to teleport players between two places in my game. When using either my scripts or ones I grabbed from the toolbox to compare to mine, the teleporter doesn’t work and I get the following error in output:
function Touch(hit)
if script.Parent.Locked == false and script.Parent.Parent:findFirstChild(Teleport).Locked == false then script.Parent.Locked = true script.Parent.Parent:findFirstChild(Teleport).Locked = true
local Pos = script.Parent.Parent:findFirstChild(Teleport)
hit.Parent:moveTo(Pos.Position) wait(1) script.Parent.Locked = false script.Parent.Parent:findFirstChild(Teleport).Locked = false end end Function.
script.Parent.Touched:connect(Touch)
Any ideas what I am doing wrong?
PS: I have also tried lentillacs teleporters and the same error is produced.
It looks like hit.Parent is equal to an accessory in this case, instead of the player character. To ensure that you are using MoveTo() on a character, you can add this check.
if hit.Parent:FindFirstChild('HumanoidRootPart') then
local Cooldown = 5
local Destination = Pos.CFrame
local dbg = true
script.Parent.Touch:Connect(function(t)
if dbg then
dbg = false
local Player = game.Players:GetPlayerFromCharacter(t.Parent)
local PlayerCharacter = nil
if Player ~= nil then
PlayerCharacter = t.Parent
if PlayerCharacter:FindFirstChild("HumanoidRootPart") ~= nil then
PlayerCharacter["HumanoidRootPart"].CFrame = Destination
end
end
wait(Cooldown)
dbg = true
end
end)