Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Teleport Script Not Working And I Have No Idea Why? (solved)

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)


2 answers

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

1 comment

0

Thanks What was wrong with my code before? was the spacing wrong?

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).

3 comments

0

oh ok thanks my bad. This is a little off topic you dont need to answer or anything but how did you learn how to code roblox lua?

0

I learned a different language first, at which point resources like http://lua-users.org/wiki/LearningLua StackOverflow and https://www.lua.org/manual/5.1/ were helpful. There are a few Lua tutorials available as well. Experimenting with scripts and trying to understand how everything works can really help.

0

oh ok thanks for your help

This discussion is preserved as it was. New answers, comments, and votes are closed.