Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Universe Teleporter GUI script doesn't work?

Newbie scripter here, thought I'd get that out of the way. Anyway, I have a SurfaceGUI on a part with a script inside of an ImageButton that says:

local TeleportService = game:GetService("TeleportService")
local id = 183840542

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

script.Parent.MouseButton1Click:connect(onClicked)

I don't really know why this isn't working. I was able to use a variation of this script using the Touched event instead of MouseButton1Click, but that was on a regular part and not a SurfaceGUI. Can anyone give me advice?

1 answer

In most cases guis should be local to each player (have their own copy of the same gui) and code also in a local script as we need to use the users input ie mouse, keyboard ect.

We are able to teleport a player in either a local script or server script the only difference being that in a local script we do not add the player as there is only ever one local player.

Example(local script):-

local TeleportService = game:GetService("TeleportService")
local id = 183840542

function onClicked()
        TeleportService:Teleport(id) -- we just teleport the player
end

script.Parent.MouseButton1Click:connect(onClicked)

I hope this helps.

2 comments

0

while this does make sense, i thought SurfaceGUIs should use server scripts since they're inside the workspace.

0

They use user input (mouse) so they need to be local in some cases, https://forum.scriptinghelpers.org/topic/19/interactive-surfaceguis

This discussion is preserved as it was. New answers, comments, and votes are closed.