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

I need help with a Teleport script [?]

Asked by 8 years ago

[Updated Again] Let me explain better. so if you click an image button, you teleport to a rp hub then you can click it again to teleport back to the last area in the rp that you were in.

This is the code:

function Teleport()
local GoTo = game.Workspace:WaitForChild("TheCastle")

if script.Parent.Value.Value == false then
    script.Parent.Value.Value = true
    p = script.Parent.Parent.Parent.Parent:WaitForChild("Head").CFrame
    script.Parent.Parent.Parent.Parent:WaitForChild("Head").CFrame = GoTo.CFrame
else
    script.Parent.Parent.Parent.Parent:WaitForChild("Head").CFrame = p
end
end

script.Parent.MouseButton1Down:connect(Teleport)


Yes, TheCastle is in workspace, yes script.Parent.Parent.Parent.Parent contains the head.

I even used

print(script.Parent.Parent.Parent.Parent) 

to prove it

errors:

Nothing appears in the output box

0
put print(script.Parent.Parent.Parent.Parent) right before line 6. 1waffle1 2908 — 8y
0
It prints "Player1" connor12260311 383 — 8y
0
put print(script.Parent.Parent.Parent:FindFirstChild("Head")) right before line 6. 1waffle1 2908 — 8y
0
well what do you know, it prints nil connor12260311 383 — 8y
View all comments (10 more)
0
meant script.Parent.Parent.Parent.Parent:FindFirstChild("Head") if that isn't what you wrote. if it is then try WaitForChild("Head") 1waffle1 2908 — 8y
0
So how would i find the head then connor12260311 383 — 8y
0
script.Parent.Parent.Parent.Parent:WaitForChild("Head") 1waffle1 2908 — 8y
0
It says argument 1 missing or nil connor12260311 383 — 8y
0
i replaced the FindFirstChild("Head") with WaitForChild("Head") and / connor12260311 383 — 8y
0
sorry about the typo, but when i replaced it, it says argument 1 missing or nil connor12260311 383 — 8y
0
what did you write 1waffle1 2908 — 8y
0
instead of p = script.Parent.Parent.Parent.Parent:FindFirstChild("Head"), i did p = script.Parent.Parent.Parent.Parent:WaitForChild("Head") connor12260311 383 — 8y
0
Oh wait nevermind, i found a typo connor12260311 383 — 8y
0
I updated the question to include my current script and answers connor12260311 383 — 8y

2 answers

Log in to vote
0
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
8 years ago

It looks like this script is running locally, which means the script is running before some of the things in the character have loaded. On line 6, WaitForChild is used to make sure that the head exists before continuing, but line 9 does not. Use WaitForChild instead of FindFirstChild on line 9.

Here's a nicer way to write it:

local head,p=script.Parent.Parent.Parent.Parent:WaitForChild("Head")
local GoTo=workspace.TheCastle
script.Parent.MouseButton1Down:connect(function()
    if script.Parent.Value.Value then
        head.CFrame=p
    else
        p=head.CFrame
        head.CFrame=GoTo.CFrame
    end
    script.Parent.Value.Value=not script.Parent.Value.Value
end)
0
It still doesnt work, i updated it again connor12260311 383 — 8y
0
re-wrote it, not sure what's going wrong with yours. script.Parent.Value.Value has to be false initially, otherwise p is undefined, but there are no errors so it is. 1waffle1 2908 — 8y
0
Still Doesnt work. connor12260311 383 — 8y
0
add script.Parent.Value.Value=not script.Parent.Value.Value after line 9. it never changes so it's never going to do something else. 1waffle1 2908 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

To answer your question, there is a YouTube channel of roblox tutorials with teleporting pads for scripting. The channel if SharQuishuhh_RBLX.

Answer this question