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

Teleportation onTouch script not working properly?

Asked by 7 years ago
Edited 7 years ago

Hello, I am trying to design a teleportation script on scratch on my own; therefore, I would appreciate that you don't give me a script to copy-paste, rather give me snippets of code that I can type down myself.

My teleportation script isn't functioning properly - it's not teleporting the player. The script is designed so that when its parent part - Teleport1 - is touched, then the script will take the player and teleport it to Teleport2, another part placed on the map.

The script doesn't seem to be working properly, as once my player touches Teleport1, nothing occurs; the player just stands on the teleportation block.

Here is the script:

local Teleport1 = script.Parent

local teleport1Usable = true

if  teleport1Usable then
    print("a")
    teleport1Usable.BrickColor = BrickColor.new("Eggplant")
else
    print("b")
    teleport1Usable.BrickColor = BrickColor.new("Really red")
    wait()
end

function onTouch(part)
    print("A")
    local humanoid = part.Parent:FindFirstChild("Humanoid")
    local targetPosition = game.Workspace.Teleport2.CFrame  


    if (humanoid ~= nil and teleport1Usable == true) then
        print("B")
        part.Parent.Character.Torso.CFrame = CFrame.new(246, 125.98, -59.211)
        teleport1Usable = false
        wait(5)
        teleport1Usable = true
    end

end

Teleport1.Touched:connect(onTouch)

I have already attempted:

~> Using the print() function to indicate whether certain parts of the script have worked: The only print() function that launched (which was in the console before and after I stepped on the teleporter) was print("a2").

~> Trying to use...

        part.Parent.Character.Torso.CFrame = CFrame.new (targetPosition.CFrame.X, targetPosition.CFrame.Y + 5, targetPosition.CFrame.Z)

... which has lead to no avail.

I believe the problem lies in the...

Teleport1.Touched:connect(onTouch)

... line of the script, as print("A2") does not do anything once Teleport1 has been Touched.

Thanks for taking your time to read; hopefully you have an answer.

0
maybe try without the function? RobloxianDestory 262 — 7y

3 answers

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

If you don't have what you want, don't kill me. If you want to make a teleporter block that regens and teleports, here ya go.

local Teleport1 = script.Parent
local teleport1Usable = true
local Teleport2 = game.Workspace.Teleport2

Teleport1.Touched:connect(function(hit)
    if hit.Parent then
        local part = hit.Parent:FindFirstChild("HumanoidRootPart")
        if part and teleport1Usable == true then
            print("a")
            Teleport1.BrickColor = BrickColor.new("Eggplant")
            part.CFrame = Teleport2.CFrame
        else
            print("b")
            Teleport1.BrickColor = BrickColor.new("Really red")
            teleport1Usable = false
            wait(2)
            Teleport1.BrickColor = BrickColor.new("Eggplant")
            wait(2)
            Teleport1.BrickColor = BrickColor.new("Medium stone gray")
            teleport1Usable = true
        end
    end
end)
0
I don't know what you did, but it worked. I'd like it if you can point out to me what I did incorrectly in the original code, though. Humding3r 2 — 7y
Ad
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

like this maybe?

script.Parent.Touched:connect(function() 

    print("A")
    local humanoid = part.Parent:FindFirstChild("Humanoid")
    local targetPosition = game.Workspace.Teleport2.CFrame  


    if (humanoid ~= nil and teleport1Usable == true) then
        print("B")
        part.Parent.Character.Torso.CFrame = CFrame.new(246, 125.98, -59.211)
        teleport1Usable = false
        wait(5)
        teleport1Usable = true
    end

end)
0
Nope; as I've already said, I don't believe the problem lies within the function, but in the connect(onTouch). Humding3r 2 — 7y
0
oh RobloxianDestory 262 — 7y
Log in to vote
0
Answered by
xEmmalyx 285 Moderation Voter
7 years ago

Line 7&10 should be using the variable 'Teleport1' instead of 'teleport1Usable'

it isn't '.Character.Torso' but '.Torso'

targetPosition should = Teleport2.Position instead of Teleport2.CFrame

You can make your life easier by replacing the exact position in the CFrame.new() with CFrame.new(targetPosition + Vector3.new(5,2,0)) -- the reason for the +Vector is so when you teleport you don't instantly teleport back from teleporting on top of the 2nd teleporter

Answer this question