Answered by
5 years ago Edited 5 years ago
LocalScripts
cannot run in global environments, that of which includes workspace
. They're meant to run on the Client, therefore are only functional in local environments. To solve your issue, simply transfer your code into a SeverScript
.
However...
Due to Filtering Enabled, ServerScripts
cannot modify local Objects—or without some loopholes—one of which includes the PlayerGui
which is used to control the User Interface To gain access to the PlayerGui
we need a Player Object, we cannot use .LocalPlayer
however since ServerScripts
aren't run on local machines, so we'll need to find an alternate way to gain access to the respective Player that needs the GUI Instance enabled.
Luckily, this isn't as hard with ClickDetectors
, since they fortunately provide the Player Object as a parameter to the Client that initiated the .MouseClick
signal.
Your issues don't stop here however, as we need to solve one last problem. As aforementioned, the PlayerGui
is the container used to manage the UI, meaning all GUI Objects are required to be a descendant of this Folder, otherwise they will not not appear or function at all. To initiate a UI, store all Instances relative into StarterGui
; they will be actively transfered to the PlayerGui
upon joining.
1 | local Clicker = script.Parent.ClickDetector |
3 | Clicker.MouseClick:Connect( function (PlayerClicked) |
4 | local PlayerGui = PlayerClicked:WaitForChild( "PlayerGui" ) |
5 | local Main = PlayerGui:WaitForChild( "Main" ) |