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

Surface GUI Teleport Problem?

Asked by 9 years ago

Im trying to make a button so it teleports me to a game and its not working! My button is in the: Part>SurfaceGui>Frame>TextButton

function onClicked(playerWhoClicked)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
        game:GetService("TeleportService"):Teleport(8473728, player)
    end
end

Thanks -littelbigblox

2 answers

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

SurfaceGuis (and also BillboardGuis) do not know the player that activated them unless the Gui itself is located within a specific Players' PlayerGui.

To start, move your SurfaceGui in its entirety to the StarterGui. Make this script a LocalScript.

Assuming 'Part' is in the Workspace, and this LocalScript is a direct descendant of the SurfaceGui:

script.Parent.Adornee = workspace.Part

function onClicked()
    if game.Players.LocalPlayer then
        game:GetService("TeleportService"):Teleport(8473728) -- The player to Teleport is assumed when called from a LocalScript.
    end
end

script.Parent.Frame.TextButton.MouseButton1Click:connect(onClicked)
Ad
Log in to vote
-1
Answered by 9 years ago
function onClicked(playerWhoClicked)
    local player = game.Players[playerWhoClicked]
    if player then
        game:GetService("TeleportService"):Teleport(8473728, player)
    end
end

Answer this question