Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer
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()

2 comments

0

If you destroy it, it won't appear again...

0

It appears again, actually. I believe it clones the Gui and puts it into the PlayerGui. Thanks alot! It works well.

This discussion is preserved as it was. New answers, comments, and votes are closed.