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

Gui Teleport Button not working please help?

Asked by 10 years ago
function onClick(Click)
    local player = game.Players:GetPlayerFromCharacter(Click.Parent)
    if player then
        game:GetService("TeleportService"):Teleport(164893711, player)
    end
end

MouseButton1Click:connect(onClick)

What im trying to do is get this button to teleport to a place im not good with gui buttons

1 answer

Log in to vote
1
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
10 years ago

You should first of all use a local script so you can get the player a lot easier. Because GUI's are different for every client, you know the player that clicked it will always be the LocalPlayer.

local player = game.Players.LocalPlayer
local gui = script.Parent -- Location of teleport GUI button

gui.MouseButton1Click:connect(function()
    game:GetService("TeleportService"):Teleport(164893711, player)
end)

The only real error you had was in your connection line. You didn't declare which GUI was effected by the event MouseButton1Click.

0
Thank you so much!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! GuardainDev 45 — 10y
Ad

Answer this question