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 5 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:

local teleportbutton1 = script.Teleport1 -- don't know why I made this

script.Teleport1.TextButton.MouseButton1Click:connect(function(m) -- teleport the player when button pressed
    p = m.Parent:findFirstChild("Humanoid")
    if p ~= nil then
        p.Torso.CFrame = CFrame.new(0,8,9) 
    end
end)
game.Workspace.Teleport1.Touched:Connect(function() -- show the button
    teleportbutton1.Enabled = true
end)
game.Workspace.Teleport1.TouchEnded:Connect(function() -- hide the button
teleportbutton1.Enabled = false
end)

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
5 years ago
Edited 5 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.

local teleportbutton1 = script.Teleport1 -- don't know why I made this

script.Teleport1.TextButton.MouseButton1Click:connect(function(PlayerWhoClicked) -- teleport the player when button pressed
    local Character = PlayerWhoClicked.Character
    local P = Character:FindFirstChildWhichIsA("Humanoid")
    if P ~= nil then
        Character:FindFirstChild("Torso").CFrame = CFrame.new(0,8,9) 
    end
end)

game.Workspace.Teleport1.Touched:Connect(function() -- show the button
    teleportbutton1.Enabled = true
end)
game.Workspace.Teleport1.TouchEnded:Connect(function() -- hide the button
teleportbutton1.Enabled = false
end)
Ad

Answer this question