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

How do I make a GUI appear with a clickdetector, then after sometime disappear?

Asked by 2 years ago

I have looked it up before, I'm not the best at scripting yet. I'm attempting to make a script when you click the door it says "It's locked." No key or anything, it just says "It's locked." Script I have (From youtube) is this:

function onClick(click)
 for i,v in pairs (script.Parent:GetChildren()) do
  if v.ClassName == "ScreenGui" then
   c = v:Clone()
   c.Parent = click.PlayerGui
  end
 end
end
script.Parent.ClickDetector.MouseClick:connect(onClick)
wait(3)
script.Parent.Parent:Destroy()

1 answer

Log in to vote
1
Answered by 2 years ago
Edited 2 years ago
function onClick(click)
    for i, v in pairs(script.Parent:GetChildren()) do
        if v.ClassName == "ScreenGui" then
            c = v:Clone()
            c.Parent = click.PlayerGui
        -- You should use wait() or task.wait() but preferably is using task.wait.
            task.wait(3) -- The amount of time you have to wait until the ScreenGui deletes.
            c:Destroy() -- Destroys the GUI.
        end
    end
end
script.Parent.ClickDetector.MouseClick:Connect(onClick) -- Also use :Connect instead of the lowercase version since is deprecated.
task.wait(3)
script.Parent.Parent:Destroy()

0
If you destroy it, it won't appear again... DarkSide_091 0 — 2y
0
It appears again, actually. I believe it clones the Gui and puts it into the PlayerGui. Thanks alot! It works well. EricAndTheWell 11 — 2y
Ad

Answer this question