Can a ClickDetector action modify a GUI?

Hello, I wrote this very simple script to open a Frame when we click on an object thanks to the ClickDetector, the action does not happen and I also do not have an error message. I wonder if the clickDetector can work with GUI? Thanks in advance

script:

local player = game.Players.LocalPlayer

local PlayerGui = player:WaitForChild(“PlayerGui”)

local MenuGui = PlayerGui.MenuGui

local Coffre = MenuGui.Coffre

local Inventory = MenuGui.Inventory

local CustomFrame = MenuGui.CustomFrame

script.Parent.MouseClick:Connect(function()

CustomFrame.Visible = false

Inventory.Visible = true

Coffre.Visible = true

end)

3 Likes

Where are you putting this script?

it does, but you did several things wrong.

LocalPlayer is non nil on the client (opposite for the server), so this would have to be a local script
but on the other hand, you apparently used this script in workspace - a local script doesn’t work there .

A ClickDetector’s MouseClick event passes the player who clicked as an argument, this can be used to access the player’s Gui and alter the properties from there.
You could just use a server script parented to the click detector


script.Parent.MouseClick:Connect(function(player)

       local PlayerGui = player:WaitForChild(“PlayerGui”)
       local MenuGui = PlayerGui:FindFirstChild("MenuGui")
       local Coffre = MenuGui.Coffre
       local Inventory = MenuGui.Inventory
       local CustomFrame = MenuGui.CustomFrame

       CustomFrame.Visible = not CustomFrame.Visible
       Inventory.Visible = not Inventory.Visible
       Coffre.Visible = not Coffre.Visible 
       -- not would basically cause it to act as a toggle on/off click detector
       -- you could just set the Visible property to true directly if you want

end)

2 Likes