I will try to use an event, ill come back with my script and tell me if its right ![]()
So this is what I suppose im doing: When I click, it fires an event.
The event opens the gui.
Then I can close the GUI without an event?
is this correct:
Script one (In serverscriptservice)
game.ReplicatedStorage.Events.Open.OnServerEvent:Connect(function(player)
player.PlayerGui.InfoBox.RockInfo.Visible = true
end)
Script 2: In game.Workspace.Stone.Primary.ClickDetector
script.Parent.MouseClick:Connect(function(player)
game.ReplicatedStorage.Events.Open:FireClient(player)
end)
Here, try this. Have 1 localscript placed under the ClickDetector part. And in it put this:
local clickDetector = script.Parent
local gui = script.Parent.Parent
local alreadyOpen = false -- Will be used below to check if the GUI is open or not
local function openGui()
if alreadyOpen == false then -- Makes gui visible only if it's closed already
gui.Visible = true
end
end
button.MouseClick:Connect(openGui) -- Uses MouseClick to connect function to click
local function closeGui()
if alreadyOpen == true then -- Makes gui invisible only if it's open already
gui.Visible = false
end
end
button.MouseClick:Connect(closeGui) -- Uses MouseClick to connect function to click
Iām sure if you use 2 different script like āLocal Scriptā and āScriptā for Open/Close Iām sure it wont work again.
What do you mean?
And Iām not sure why people are saying to use Remote Events in the first place when it seems oddly unnecessary for such a simple task. Just use a localscript like I showed above!
So I am not sure what you mean everyone. To open the gui you click the part. To close it there is a little X in the corner, you do not click it again.
Ohh I see. The code you shared earlier got me confused as to what exactly youāre doing.
In the code below I fitted it to what you said, and got rid of some unecessary parts I realized I had in there.
Put the code below in a localscript, placed under the clickDetectorPart - Note: You can put it wherever you want locally, as long as you change the variables correctly; but keep the code in a single localscript.
Here:
local clickDetectorPart = script.Parent
local gui = -- Path to gui you want to make visible/invisible
local guiButton = -- Path to the X button for gui
local function openGui()
if gui.Visible == false then -- Makes gui visible only if it's closed already
gui.Visible = true
end
end
clickDetectorPart.MouseClick:Connect(openGui) -- Connects function to clicking clickDetectorPart
local function closeGui()
if gui.Visible == true then -- Makes gui invisible only if it's open already
gui.Visible = false
end
end
guiButton.MouseButton1Click:Connect(closeGui) -- Connects function to clicking guiButton
NOTE: Make sure you fill in the variables at the top to whatever they are.
Let me know how it works out!
Sorry for the long wait! I needed to go to school. I am testing it rn and will come back with results
@MJTFreeTime Did not work, why?
Your original method, modified:
script.Parent.MouseClick:Connect(function(player)
player.PlayerGui.InfoBox.GoldInfo.Visible = false
player.PlayerGui.InfoBox.GoldInfo.Visible = true
end)
Using Remote Events:
Server:
local ClickDetector = script.Parent
local RemoteEvent = Instance.new("RemoteEvent", game.ReplicatedStorage)
RemoteEvent.Name = "MakeGuiVisible"
ClickDetector.MouseClick:Connect(function(plyr)
RemoteEvent:FireClient(plyr)
end)
LocalScript:
local Remote = game.ReplicatedStorage:WaitForChild("MakeGuiVisible")
Remote.OnClientEvent:Connect(function()
Gui.Visible = true
end)
Trying this now!!! Hope it works!
Could you not just
script.Parent.MouseClick:Connect(function(player)
player.PlayerGui.InfoBox.GoldInfo.Visible = not player.PlayerGui.InfoBox.GoldInfo.Visible
end)
Sorry If I was missing something I kinda skipped through the thread so I might have just gone straight back into the problem you had.
EDIT: You would also want this in a local script instead of the server to make it easier than having to go through remote events, unless that is the thing that you want to avoid then apologies ![]()
Where do I put this script? I am confusion
@kylerzong this script is the issue
@badle144 didnt workkkkkkkkkkk why
Most probably this is because you closed the UI via the Gui.
May be try this
local visible = false
script.Parent.MouseClick:Connect(function(player)
if visible == false then
player:WaitForChild("PlayerGui").InfoBox.GoldInfo.Visible = true
visible = true
end
end)
function closeGui(player)
if visible = true then
local PlayerGui = player:WaitForChild("PlayerGui")
PlayerGui.InfoBox.CloseButton.MouseButton1Up:Connect(function() --- go to the UI which closes the Main GUI(This is just an example)
PlayerGui.InfoBox.GoldInfo.Visible = false
visible = false
end)
end
end
(NOTE : SCRIPT IS INSIDE THE PART WHICH HAS THE CLICK DETECTOR)
Sorry for the long wait! I am testing this now ![]()
That is in your localscript where you would make the gui visible after receiving an event from the server scriptā¦
It is tested and working, you must not have set it up correctly
the Gui Variable would be something like āGui = script.Parent.Frameā
GuiBtn.rbxl (24.9 KB)