I want to enable a ScreenGui I have in StarterGui by clicking on a part.
No errors in output, nothing happens when I click on the part.
Can someone please tell me what I am doing wrong?
-- LocalScript inside StarterPlayerScripts local player = game.Players.LocalPlayer local mouse = player:GetMouse() local gui = game.StarterGui.WeaponsGui -- path to WeaponsGui mouse.Button1Down:Connect(function() if mouse.Target and mouse.Target.Name == "GuiGiver" then local clickDetector = mouse.Target:FindFirstChild("ClickDetector") if clickDetector then gui.Enabled = true end end end)
I couldn’t test my code so sorry if anything is wrong.
So there’s one mistake that is REALLY sticking out to me (and surprisingly no one noticed it yet) and that is line 5 on your code. You’re trying to enable your GUI through StarterGui, which won’t work as StarterGui clones all GUI in it into players that joined/respawned. What you’re trying to get to is PlayerGui, which is in the player.
Here’s what your code should look like :
-- LocalScript inside StarterPlayerScripts local player = game:GetService('Players').LocalPlayer local mouse = player:GetMouse() local gui = player:WaitForChild('PlayerGui').WeaponsGui -- path to WeaponsGui mouse.Button1Down:Connect(function() if mouse.Target and mouse.Target.Name == "GuiGiver" then local clickDetector = mouse.Target:FindFirstChild("ClickDetector") if clickDetector then gui.Enabled = true end end end)
Now, since I can’t test this, I can’t guarantee the code works, but I’m sure that you have to enable it through PlayerGui.
Also note that if you switch back to using the MouseClick event on the clickdetector, it may or may not work. I forgot if the event works locally but if it doesn’t work, you’ll have to use remote events.
Hope this helped!
Please put a ClickDetector in the part and instert this script!
script.Parent.MouseClick:Connect(function(plr) plr.PlayerGui.WeaponsGui.Enabled = true end)
This short simple code will make it work fine!
Hello! This is question actually has a simple answer. See, the enabled part of your script is the reason. Enabled is read-only, so it can't be edited.
Instead, use Visible for the text label/frame in order to do this. Thanks!
The problem is mostly with the ClickDetector object. It's annoying to get around. If your script is a local script inside the click detector, that won't work cause localscripts only run under player objects. One solution would be to check on the client side for this click detector.
-- LocalScript inside StarterPlayerScripts local player = game.Players.LocalPlayer local mouse = player:GetMouse() local gui = -- path to WeaponsGui mouse.Button1Down:Connect(function() if mouse.Target and mouse.Target.Name == "NameOfObjectHoldingClickDetector" then local clickDetector = mouse.Target:FindFirstChild("ClickDetector") if clickDetector then gui.Enabled = true end end end)
Hope this helps!