Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)

1 comment

0

maybe you can do is check first if the GUI is closed or not

2 answers

✓ Accepted answer

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

2 comments

0

Ive access the player gui via a server script before.

0

As far as I know, you cannot modify the contents of the PlayerGui from the server. I'm sure you can access it.

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

This discussion is preserved as it was. New answers, comments, and votes are closed.