Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years ago

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

Log in to vote
1
Answered by
InLeXiX 18
4 years ago
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

0
Thanks What was wrong with my code before? was the spacing wrong? Pigred72 0 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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

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? Pigred72 0 — 4y
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. chess123mate 5873 — 4y
0
oh ok thanks for your help Pigred72 0 — 4y

Answer this question