local clickdetector = game.Workspace.npc1.Head.ClickDetector
local frame1 = game.StarterGui.DialogueGui1.Frame
frame1.Visible = false
clickdetector.MouseClick:Connect(function()
if frame1.Visible == false then
frame1.Visible = true
end
end)
Here I have a fairly simple script. But whenever I test the game, the gui stays visible. I’m not getting any errors in command output. What am I doing wrong?
you’re referring to the StarterGui instead of the player themselves.
this means game:GetService(“Players”).LocalPlayer.PlayerGui instead of StarterGui
you can also use script.Parent depending on where your script is
P.S: it has to be a local script
StarterGui is a service, making changes to it won’t replicate. You instead need to reference to the individual player’s PlayerGui.
local clickdetector = workspace.npc1.Head.ClickDetector
clickdetector.MouseClick:Connect(function(player) -- Player is a parameter of MouseClick
local frame1 = player:WaitForChild('PlayerGui').DialogueGui1.Frame
if frame1.Visible == false then
frame1.Visible = true
end
end)