So this is a script inside a part called "HandleGlow", and it makes a door locked sound, and show a GUI with a text label saying: "Its locked". however, when I clicked it, everything worked, the output printed "WORKED!", the sound played, but the GUI didnt show up. Here is the script below. Please help me!
01 | local clickDetector = script.Parent.ClickDetector |
02 | --Mouse hover stuff VVVVVVV-- |
03 | script.Parent.ClickDetector.MouseHoverEnter:Connect( function () |
04 |
05 | script.Parent.Parent.HandleGlow.Transparency = 0.75 |
06 | end ) |
07 | --Mouse Leave stuff VVVVV--- |
08 | script.Parent.ClickDetector.MouseHoverLeave:Connect( function () |
09 | script.Parent.Parent.HandleGlow.Transparency = 1 |
10 | end ) |
11 | --Door Stuff VVVVVV-- |
12 | function onMouseClick() |
13 | script.Parent.DoorLocked:Play() |
14 | local A = game.StarterGui:FindFirstChild( "LockedMessage" ) |
15 | A.Enabled = true |
startergui, not playergui
and next: playergui is not accessible via serverscript. you'll have to use a remoteevent/remotefunction in order to communicate to the client via server.
for example:
1 | --serverscript |
2 | workspace.Event:FireClient(params) --send message to certain player |
1 | --localscript |
2 | workspace.Event.OnClientEvent:Connect( function (params) |
3 |
4 | game.Players.LocalPlayer.PlayerGui.LockedMessage.Enabled = true ; --set LockedMessage's enabled property to true |
5 |
6 | end ) |
however, remotefunctions work a bit differently:
1 | --serverscript |
2 | workspace.Event:InvokeClient(params) --send message to certain player |
1 | --localscript |
2 | workspace.Event.OnClientInvoke = function (params) --DIRECTLY set the Event's OnClientInvoke "property" to a function that is called via the InvokeClient method |
3 |
4 | game.Players.LocalPlayer.PlayerGui.LockedMessage.Enabled = true ; |
5 |
6 | end |
for more info on this kind of stuff: https://scriptinghelpers.org/questions/68579/can-someone-help-me-fix-devil-beater-im-not-100-sure-how-this-fe-stuff-works#65698
The reason that it isn't showing the gui is that your enabling the gui in the starter gui. You need to enable it in the Player gui. Here is your revised code:
01 | local clickDetector = script.Parent.ClickDetector |
02 |
03 | --Mouse hover stuff VVVVVVV-- |
04 | script.Parent.ClickDetector.MouseHoverEnter:Connect( function () |
05 | script.Parent.Parent.HandleGlow.Transparency = 0.75 |
06 | end ) |
07 |
08 | --Mouse Leave stuff VVVVV--- |
09 | script.Parent.ClickDetector.MouseHoverLeave:Connect( function () |
10 | script.Parent.Parent.HandleGlow.Transparency = 1 |
11 | end ) |
12 |
13 | --Door Stuff VVVVVV-- |
14 | function onMouseClick(Plr) |
15 | local PlrGui = Plr:WaitForChild( "PlayerGui" ) |
Happy coding to you