Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Gui will not re-open in servers!?

Asked by 6 years ago
Edited 6 years ago

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!

0
Just make the Gui Enabled true or Enabled false and if theres anything particular you need to do then juts make specific frames/boxes visible using :clone() and :destroy() probably won't work as expectes using this method abnotaddable 920 — 6y
0
^^^ has a point. H4X0MSYT 536 — 6y
0
How would I write that out in the script? Sorry, I don't have much experience with guis Skepticlemon 24 — 6y

1 answer

Log in to vote
0
Answered by
arshad145 392 Moderation Voter
6 years ago
Edited 6 years ago

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.

0
Thanks for the help, however, it still doesn't seem to work. The gui is located in the object, but even after modifying it to locate the gui, it still won't open the second time the player tries to touch the block. Skepticlemon 24 — 6y
0
It's also worth noting that the local script doesn't change the gui enable value either. Skepticlemon 24 — 6y
0
Check if game.workspace.FilteringEnabled prints false by doing : print(workspace.FilteringEnabled) arshad145 392 — 6y
0
Also screenshot your game explorer so that I can get a better idea of what you are trying to do. arshad145 392 — 6y
View all comments (7 more)
0
http://imgur.com/a/8V6s5 This is the whole system itself. Hopefully this can help. Skepticlemon 24 — 6y
0
More updates ~ Filtering enabled comes up with true and I found that once the gui opens for the player, it deletes itself. I don't know why but it does. Skepticlemon 24 — 6y
0
Another update ~ The gui gets moved into the PlayerGui, removing it from the block and that's why it disappears. Skepticlemon 24 — 6y
0
Where is the part named "gui" located? arshad145 392 — 6y
0
just in the workspace. Skepticlemon 24 — 6y
0
Sorry , please a bit more. I am currently busy. Sorry. arshad145 392 — 6y
0
Should work now! Thank you for your cooperation to solve your issue. arshad145 392 — 6y
Ad

Answer this question