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

Why does this localscript for a SurfaceGui only work in PlaySolo?

Asked by
Stravan 18
6 years ago
Edited 6 years ago
local TeleportService = game:GetService("TeleportService")
local id = 364386074
local button = game.Workspace.LocationHologram.Hologram.SurfaceGui.ImageButton

function onClicked()
        TeleportService:Teleport(id)
end

button.MouseButton1Click:connect(onClicked)

This LocalScript only seems to work in PlaySolo, and not the actual server. I figured it was because it wasn't supposed to be a LocalScript. So, I tried this script using a ServerScript and rerouted the button variable but it still didn't work. Does anyone know why?

0
Are you using Filtering Enabled? KingLoneCat 2642 — 6y
0
Make it a ServerScript. User#2146 0 — 6y
0
No, I'm not using FilteringEnabled. And also, I've tried using a ServerScript as I said in the post. But it still didn't work. Stravan 18 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

I believe this is quite easy to fix!

The TeleportService arguments contain a few arguments that you should include. (player is not required in LocalScript but you never know, it's always nice to include)

I believe your code should be:

local TeleportService = game:GetService("TeleportService")
local id = 364386074
local button = game.Workspace.LocationHologram.Hologram.SurfaceGui.ImageButton

function onClicked()
        TeleportService:Teleport(id, game.Players.LocalPlayer)
end

button.MouseButton1Click:connect(onClicked)


This is because you're not telling the server who you're actually teleporting (even in a local script). Sorry if this is incorrect, but from my knowledge of TeleportService, I believe this should solve your problem!

If this does not solve your problem then it is most likely an issue with your event. Attempt to change MouseButton1Click to MouseButton1Down

Hope this helped! :)

0
Unfortunately, this did not resolve the issue. I changed the event and included the extra argument but nothing changed. Thanks for trying to help though! Stravan 18 — 6y
Ad

Answer this question