Hey, so I have a script that opens a gui and it has a line that stops the gui from opening multiple times and layering, however, when I added that line of code, it stopped the gui opening again after you closed it the first time. This only happens in servers, it works fine in solo, but I understand that solo testing is a lot more lenient. I also believe that it may be a line of code that closes the gui in the local script that may be causing this. I'm just asking for some help for a fix, thanks.
This is the script that opens the gui ontouch
local debounce = true script.Parent.Touched:connect(function(hit) local hum = hit.Parent:FindFirstChild("Humanoid") if hum ~= nil and debounce == true then local player = game.Players:FindFirstChild(hum.Parent.Name) if not player.PlayerGui:FindFirstChild("FrameWork") then -- Checks if the object 'FrameWork' is really inside of the PlayerGui. If it's not then it will pass the if statement. debounce = false local Gui = script.Parent.FrameWork:clone() Gui.Parent = player.PlayerGui wait(1) debounce = true end end end)
This script is the response after you click an option, after showing the response, it should close the gui.
text = { "Your loss! You can return at anytime if you change your mind." } function Click() wait() script.Parent.Visible = false script.Parent.Parent.Button1.Visible = false local randText = text[math.random(#text)] for a=1,string.len(randText) do script.Parent.Parent.Dialog.Text = string.sub(randText,1,a).."" wait(.01) end wait(5) local gui = script.Parent.Parent.Parent gui:Destroy() end script.Parent.MouseButton1Down:connect(Click)
The script should open a gui when touched a block then close it after 4 seconds after you pick an option. It does that fine, but it does not re-open after the gui exits. Thanks!
So let me start.
The Hierarchical order of ScreenGui is : Rbx Studio
Now that I have assumed all that :
Script in game.workspace.gui("Part")
local debounce = true -- Variable. script.Parent.Touched:connect(function(hit) --When gui part is touched. local hum = hit.Parent:FindFirstChild("Humanoid") -- Checks if an object or a player hit the part. if hum ~= nil and debounce == true then -- if a human/player hit the part : local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- This is more efficient than getting Humanoid.Name. if player.PlayerGui:FindFirstChild("FrameWork") == nil then -- Check if "FrameWork", is not inside of Gui. debounce = false -- Turns debounce to false to prevent duplication of function execution. local Gui = script.Parent:findFirstChild("FrameWork")--According to my assumptions.(You can change to your directory) local g1 = Gui:Clone() --According to your directory,You need to clone the Gui. g1.Parent = player.PlayerGui --Parented to player's PlayerGui. g1.Enabled = true -- Enabled the Gui for the player to see it on the screen. g1.FrameWork.Size = UDim2.new(0.25,0,0.5,0) -- Declare the FrameWork size g1.FrameWork.Button1.Size = UDim2.new(1,0,0.5,0) g1.FrameWork.Button1.Position = UDim2.new(0,0,0.5,0) g1.FrameWork.ZIndex = 1 --Makes the gui last. g1.FrameWork.Dialog.ZIndex = 3 -- Dialog appears above all guis. g1.FrameWork.Button1.ZIndex = 2 -- Button1 is on top of gui. wait(1) debounce = true -- Prevents the function from running twice. else local g = player.PlayerGui:FindFirstChild("FrameWork") --If FrameWork is already in PlayerGui then just .Enabled = true g.Enabled = true debounce = true -- Allow the next touch event to parse. end end end)
Localscript inside of playerGui.FrameWork.Button1("TextButton")
text = { "Your loss! You can return at anytime if you change your mind." } function Click() -- A function. wait() local randText = text[math.random(#text)] --Random effect of entering characters. for a=1,string.len(randText) do script.Parent.Parent.Dialog.Text = string.sub(randText,1,a).."" -- Text changes to "text". wait(.01) end wait(5) local gui = script.Parent.Parent.Parent -- Gui is allocated here. script.Parent.Parent.Dialog.Text = "Text" -- Initialise Text of Dialog to "Text" gui.Enabled = false -- Use .Enabled = false ; instead of :Destroy() with Guis. end script.Parent.MouseButton1Down:connect(Click) --Your mistake was that you were disabling both Button1 and FrameWork("Frame")
That's it!
I am still learning RbxLua.
Thank you for reading.