Hi, Im trying to get my teleporting script working and it's saying there's a problem but I don't know what it is. sorry I'm really new at coding Lua
local Teleport1A = script.Parent local Teleport1B = script.Parent.Teleport1B local canTeleport = true function TeleportA(part) local hum = part.Parent:FindFirstChild ("HumanoidRootPart") if hum then if canTeleport then canTeleport = false hum.CFrame = Teleport1B.CFrame + Vector3. new(0,5,0) wait(5) canTeleport = true end end end function TeleportB(part) local hum = part.Parent:FindFirstChild ("HumanoidRootPart") if hum then canTeleport = false hum.CFrame = Teleport1A.CFrame + Vector3. new(0,5,0) wait(5) canTeleport = true end end end Teleport1A.Touched:Connect(TeleportA) Teleport1B.Touched:Connect(TeleportB)
local Teleport1A = script.Parent local Teleport1B = script.Parent.Teleport1B local canTeleport = true function TeleportA(part) local hum = part.Parent:FindFirstChild("HumanoidRootPart") if hum then if canTeleport then canTeleport = false hum.CFrame = Teleport1B.CFrame + Vector3.new(0,5,0) wait(5) canTeleport = true end end end function TeleportB(part) local hum = part.Parent:FindFirstChild("HumanoidRootPart") if hum then if canTeleport then canTeleport = false hum.CFrame = Teleport1A.CFrame + Vector3.new(0,5,0) wait(5) canTeleport = true end end end Teleport1A.Touched:Connect(TeleportA) Teleport1B.Touched:Connect(TeleportB)
It should work now
In Roblox Studio, go to the View menu and open up the Output and Script Analysis windows. The Output window tells you when the script runs into a problem; the Script Analysis window can sometimes tell you when you have an error before you even run them (and also warn you about things that are probably wrong).
The problem in this case is that you don't need to put ("HumanoidRootPart")
on its own line - in fact, this is the problem that the Script Analysis window complains about (due to how Lua works). You have other cases where you spread out one function call onto two lines (like Vector3.new
), which - for clarity - should also be put back into a single line (as InLeXiX showed).