Trying to make it so when you click a button on my teleport GUI, a preview of a location will pop up and the teleport button will as well, which you can then click to teleport. I'm having issues with the script. It's saying StarterGui doesn't exist in the global space ("W001: Unknown global 'StarterGui') when it definitely does. Furthermore, I am just new to scripting in general and would like to know if this would work without that error anyway, so any feedback on that would be helpful too. Thanks!
local lobbypreview = StarterGui.TeleportMenu.Frame.Preview.Lobby local teleport = StarterGui.TeleportMenu.Telebuttoncurrent script.Parent.MouseButton1Click:Connect(leftClick) function leftClick ()lobbypreview.Visible = true teleport.Visible = true end
All guis in StarterGui
will be replicated to PlayerGui
which is in the player once the game start running, so you have to change the variable path to game:GetService("Players").LocalPlayer.PlayerGui
. If you don't understand what I mean, try this.
local plr = game:GetService("Players").LocalPlayer local plrGui = plr:WaitForChild("PlayerGui") local lobbypreview = plrGui:WaitForChild("TeleportMenu"):WaitForChild("Frame"):WaitForChild("Preview"):WaitForChild("Lobby") --The GuiObjects may not be replicated yet, we have to wait for them. local teleport = plrGui.TeleportMenu:WaitForChild("Telebuttoncurrent") script.Parent.MouseButton1Click:Connect(leftClick) function leftClick() lobbypreview.Visible = true teleport.Visible = true end
It must be done in LocalScript.