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

How do you have a TextButton teleport a player somewhere?

Asked by
stix619 15
10 years ago

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

Log in to vote
1
Answered by
jobro13 980 Moderation Voter
10 years ago

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)


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. stix619 15 — 10y
0
Nevermind! It worked. Thank you! stix619 15 — 10y
0
No problem! jobro13 980 — 10y
Ad
Log in to vote
1
Answered by 10 years ago

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

Answer this question