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

Script dosent work despite "WORKED!" Being printed, and no errors in output?

Asked by 4 years ago

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!


local clickDetector = script.Parent.ClickDetector --Mouse hover stuff VVVVVVV-- script.Parent.ClickDetector.MouseHoverEnter:Connect(function() script.Parent.Parent.HandleGlow.Transparency = 0.75 end) --Mouse Leave stuff VVVVV--- script.Parent.ClickDetector.MouseHoverLeave:Connect(function() script.Parent.Parent.HandleGlow.Transparency = 1 end) --Door Stuff VVVVVV-- function onMouseClick() script.Parent.DoorLocked:Play() local A = game.StarterGui:FindFirstChild("LockedMessage") A.Enabled = true wait(5) A.Enabled = false print("WORKED!") end clickDetector.MouseClick:connect(onMouseClick)
0
maybe you can do is check first if the GUI is closed or not manzano30 5 — 4y

2 answers

Log in to vote
1
Answered by
Fifkee 2017 Community Moderator Moderation Voter
4 years ago
Edited 4 years ago

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:

--serverscript
workspace.Event:FireClient(params) --send message to certain player
--localscript
workspace.Event.OnClientEvent:Connect(function(params)

    game.Players.LocalPlayer.PlayerGui.LockedMessage.Enabled = true; --set LockedMessage's enabled property to true

end)

however, remotefunctions work a bit differently:

--serverscript
workspace.Event:InvokeClient(params) --send message to certain player
--localscript
workspace.Event.OnClientInvoke = function(params) --DIRECTLY set the Event's OnClientInvoke "property" to a function that is called via the InvokeClient method

    game.Players.LocalPlayer.PlayerGui.LockedMessage.Enabled = true;

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

0
Ive access the player gui via a server script before. MrCatDoggo 213 — 4y
0
As far as I know, you cannot modify the contents of the PlayerGui from the server. I'm sure you can access it. User#29813 0 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

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:

local clickDetector = script.Parent.ClickDetector

--Mouse hover stuff VVVVVVV--
script.Parent.ClickDetector.MouseHoverEnter:Connect(function() 
    script.Parent.Parent.HandleGlow.Transparency = 0.75
end)

--Mouse Leave stuff VVVVV---
script.Parent.ClickDetector.MouseHoverLeave:Connect(function()
    script.Parent.Parent.HandleGlow.Transparency = 1
end)

--Door Stuff VVVVVV--
function onMouseClick(Plr)
    local PlrGui = Plr:WaitForChild("PlayerGui")
    local Gui = PlrGui:WaitForChild("LockedMessage")
    script.Parent.DoorLocked:Play()
    Gui.Enabled = true
    wait(5)
    Gui.Enabled = false
    print("WORKED!")
end

clickDetector.MouseClick:connect(onMouseClick)

Happy coding to you

Answer this question