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 10 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

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

Thanks -littelbigblox

2 answers

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
10 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:

1script.Parent.Adornee = workspace.Part
2 
3function onClicked()
4    if game.Players.LocalPlayer then
5        game:GetService("TeleportService"):Teleport(8473728) -- The player to Teleport is assumed when called from a LocalScript.
6    end
7end
8 
9script.Parent.Frame.TextButton.MouseButton1Click:connect(onClicked)
Ad
Log in to vote
-1
Answered by 10 years ago
1function onClicked(playerWhoClicked)
2    local player = game.Players[playerWhoClicked]
3    if player then
4        game:GetService("TeleportService"):Teleport(8473728, player)
5    end
6end

Answer this question