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

How do you have a TextButton teleport a player somewhere?

I have finally created a TextButton GUI on the edge of the screen (So happy about it too :P), and put in a script that would cause teleportation on click. However, it is not working.

Here is the code I am using.

bin = script.Parent

function onClick() 
    if Part.Parent:FindFirstChild("Torso") then 
        Part.Parent.Torso.CFrame = CFrame.new(Vector3.new(84, 160, 12))
    end
end

bin.MouseButton1Click:connect(onClick)

I suspect it has something to do with the variable or the function. If you could, may you put comment snippets in the code to show where you changed something?

Thank you in advance.

Edit: Also, where should I put the script? I have a ScreenGUI, which is a parent to TextButton, which the script is in. Is this correct?

2 answers

✓ Accepted answer

You indeed didn't set what Part is. My guess is that part should be your character.

bin = script.Parent

Part = game.Players.LocalPlayer.Character

function onClick() 
    if Part:FindFirstChild("Torso") then 
        Part.Torso.CFrame = CFrame.new(Vector3.new(84, 160, 12))
    end
end

bin.MouseButton1Click:connect(onClick)


3 comments

0

I'm edited to code to show the changes, and I'm clicking the GUI, but it is not teleporting me. I'm looking through the code again to see if I copied something wrong.

0

Nevermind! It worked. Thank you!

0

No problem!

You didnt set what part is (i mean, part is not a variable), so then the script breakes. Tip: let output open when you test something, there it will show the errors( the text thats on red).

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