I’m trying to make it where when you click on a part, something will happen only if a GUI is open. For example right now I have it where when you click a part a GUI will open. I want to make it where when you click on another part it will only doing something if that GUI is open. I’m kinda new to scripting and needed a little help with this.
Ill just tell you what I have at the moment. So far I have a local script in StarterPlayerScripts:
local gui = game.StarterGui.ScreenGui.ImageLabel
if gui.Visible == true then
function onClicked()
print("hi")
end
workspace.coin.ClickDetector.MouseClick:connect(onClicked)
end
Then I also have a screen GUI in StarterGui with a local script:
local function VisibilityChange()
local gui = script.Parent
gui.Visible = true
end
game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(VisibilityChange)
Then I have a part called coin and a part in Workspace. And inside the parts are ClickDetectors and inside the part named part is a script:
local function onClicked(plr)
game.ReplicatedStorage.RemoteEvent:FireClient(plr)
end
workspace.Part.ClickDetector.MouseClick:Connect(onClicked)
Lastly I have a RemotEvent in ReplicatedStorage.
Too sum it up all I’m trying to do is make it where something will happen when a part is clicked. That certain thing will only happen if a certain GUI is visible. When I click on one part a GUI becomes visible but when I click on the other part nothing happens. Sorry if I made this longer then it should be. Thanks
No, only the person who clicks on the grey part. But I already coded it where when the player clicks on the grey part a GUI becomes visible. I just want it where when they click on the yellow part something will happen but only if that GUI is visible. Sorry if I’m making it too complicated.
So this code isn’t working for some reason:
local gui = game.Players.LocalPlayer.PlayerGui:WaitForChild("ScreenGui").ImageLabel
if gui.Visible == true then
function onClicked()
print("hi")
end
workspace.coin.ClickDetector.MouseClick:connect(onClicked)
end
local gui = game.Players.LocalPlayer.PlayerGui:WaitForChild("ScreenGui").ImageLabel
function onClicked()
if gui.Visible == true then
print("hi")
end
end
workspace.coin.ClickDetector.MouseClick:Connect(onClicked)