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

How to make a gui teleport function?

Asked by 6 years ago

So I'm trying to make it so that if a player touches a part, a button pops up When they press that button, it teleports that player. If you can, please post me a working script. If you just want to bug-fix mine, feel free:

01local teleportbutton1 = script.Teleport1 -- don't know why I made this
02 
03script.Teleport1.TextButton.MouseButton1Click:connect(function(m) -- teleport the player when button pressed
04    p = m.Parent:findFirstChild("Humanoid")
05    if p ~= nil then
06        p.Torso.CFrame = CFrame.new(0,8,9)
07    end
08end)
09game.Workspace.Teleport1.Touched:Connect(function() -- show the button
10    teleportbutton1.Enabled = true
11end)
12game.Workspace.Teleport1.TouchEnded:Connect(function() -- hide the button
13teleportbutton1.Enabled = false
14end)

All of the parts & things are in the right place, and it's in a LocalScript

1 answer

Log in to vote
0
Answered by
Despayr 505 Moderation Voter
6 years ago
Edited 6 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.

Try this. You tried to reference the Torso inside of the Humanoid, but the Torso is located inside of the character.

01local teleportbutton1 = script.Teleport1 -- don't know why I made this
02 
03script.Teleport1.TextButton.MouseButton1Click:connect(function(PlayerWhoClicked) -- teleport the player when button pressed
04    local Character = PlayerWhoClicked.Character
05    local P = Character:FindFirstChildWhichIsA("Humanoid")
06    if P ~= nil then
07        Character:FindFirstChild("Torso").CFrame = CFrame.new(0,8,9)
08    end
09end)
10 
11game.Workspace.Teleport1.Touched:Connect(function() -- show the button
12    teleportbutton1.Enabled = true
13end)
14game.Workspace.Teleport1.TouchEnded:Connect(function() -- hide the button
15teleportbutton1.Enabled = false
16end)
Ad

Answer this question