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

I need help with a Teleport script [?]

[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

14 comments

0

put print(script.Parent.Parent.Parent.Parent) right before line 6.

0

It prints "Player1"

0

put print(script.Parent.Parent.Parent:FindFirstChild("Head")) right before line 6.

0

well what do you know, it prints nil

0

meant script.Parent.Parent.Parent.Parent:FindFirstChild("Head") if that isn't what you wrote. if it is then try WaitForChild("Head")

0

So how would i find the head then

0

script.Parent.Parent.Parent.Parent:WaitForChild("Head")

0

It says argument 1 missing or nil

0

i replaced the FindFirstChild("Head") with WaitForChild("Head") and /

0

sorry about the typo, but when i replaced it, it says argument 1 missing or nil

0

what did you write

0

instead of p = script.Parent.Parent.Parent.Parent:FindFirstChild("Head"), i did p = script.Parent.Parent.Parent.Parent:WaitForChild("Head")

0

Oh wait nevermind, i found a typo

0

I updated the question to include my current script and answers

2 answers

✓ Accepted answer

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)

4 comments

0

It still doesnt work, i updated it again

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.

0

Still Doesnt work.

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.

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

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