#How to destroy gui after 2 secs

1 messages · Page 1 of 1 (latest)

sour plaza
#

i have this script but i want to make it so after the wait(2) the part will get destroyed but i dont know how because i dont have the part as variable.

heres the script: local Prompt = script.Parent

Prompt.Triggered:Connect(function()
h = Instance.new("Message")
h.Parent = game.Workspace

while true do
    h.Text = "Interacted!"
    wait(2)  
    
end

end)

worldly junco
#

Hey!! @sour plaza I'm not very sure but i think there is the correct script : local Prompt = script.Parent

Prompt.Triggered:Connect(function()
local h = Instance.new("Message")
h.Text = "Interacted!"
h.Parent = game.Workspace

wait(2)
h:Destroy()

end)

sour plaza
worldly junco
#

Oh okk

lament moss
#

Also if you don't want to yield the entire code you can use game:GetService("Debris"):AddItem(item,time) this will queue an instance to be destroyed after a said time.
It's also good to note that wait() has been deprecated and you should use task.wait() instead.

worldly junco
#

Gl for your game!!

sour plaza
lament moss
#

You use game:GetService(name) to get a service from the roblox api. Then AddItem() is a function provided by the "Debris" service

#

Services are for example: workspace, Players, ReplicatedStorage and other which may not be visible in the explorer

fringe crown
sour plaza
fringe crown
#

heres something i found on the roblox website

wait() can sometimes delay when it resumes the thread because of performance concerns, which is actually bad because you will rarely have those because of it

task.wait() updates 2x faster than wait(), therefore more accurate

sour plaza
#

btw, do you know how to make things activate only when you double click on a part?

fringe crown
#

in general if anything is depreciated you should use it

fringe crown
#

you can see how long ago the last click was and if its smaller then a certain amount of time you can run a function

sour plaza
#

can you show me like a script example

patent glacier
#

someon ehelp me pls

#

allah

fringe crown
# sour plaza can you show me like a script example
local CD = script.Parent -- put path to click detector (or other thing) here
local lastClick = 0 -- puts at 0 to reset
local maxTime = 1 -- max delay between ticks (in seconds)

CD.MouseClick:Connect(function(plr) -- detect when clicked
    if (tick() - lastClick) < maxTime then -- detect if the current tick - last click tick is less then max time
        lastClick = 0 --reset so clicking again in quick sucsession does not do more (so 3 clicks do not activate it 2 times)
        
        print("Double clicked") -- put logic here
        
    else
    lastClick  = tick() -- set last click when not short enough time
    end
end)
sour plaza
#

my brain is too small to understand

fringe crown
# sour plaza my brain is too small to understand

basicaly it stores when you last clicked (lastClick) everytime you click
if the current time - the time of the last click is larger the max time it does not work
if the current time - the time of the last click is smaller then it runs the code

sour plaza
#

uh

#

so the script parent is the part

#

that is supposed to be double clicked on

fringe crown
#

the script parent is whatever your using to detect the clicks

#

(usually a click detector)

sour plaza
#

oh

#

so i put a click detector in a part and inside the click detector the script

fringe crown
#

yes

#

part
l__Click detector
l__script

#

if its a screen gui it would need to be a textbutton or an imagebutton

sour plaza
#

welp

fringe crown
#

and you would use MouseButton1Click

sour plaza
#

doesnt work

fringe crown
sour plaza
#

oh

#

wait

fringe crown
#

and how the ansestory works?

sour plaza
#

lemem fix ti

fringe crown
#

ok 👍

sour plaza
#

but theres one error....

fringe crown
#

whats the error?

mossy cosmosBOT
#

studio** You are now Level 5! **studio

fringe crown
#

yay im deep yellow now :)

sour plaza
fringe crown
#

can i see that script?

sour plaza
#

uh

#

the script is too long to send on discord

fringe crown
#

can i see the line thats erroring?

sour plaza
#

but i deleted it

fringe crown
#

hmmm

#

idk much about replacing sonds and animations

sour plaza
#

and i got one more question

#

how do i add cooldown to it

#

like a 2 second cooldown

fringe crown
#

to the doubleclick?

sour plaza
#

so it cant be spammed

fringe crown
#

one sec

#
local CD = script.Parent -- put path to click detector (or other thing) here
local lastClick = 0 -- puts at 0 to reset
local maxTime = 1 -- max delay between ticks (in seconds)

local debounce = false -- no debounce to start
local debounceDelay = 2 -- how long do wait before clickable again

CD.MouseClick:Connect(function(plr) -- detect when clicked
    if not debounce then
        if (tick() - lastClick) < maxTime then -- detect if the current tick - last click tick is less then max time
            lastClick = 0 --reset so clicking again in quick sucsession does not do more (so 3 clicks do not activate it 2 times)
            debounce = true -- stop from being run again
            task.delay(2,function()
                debounce = false -- make it clickable again
            end)

            print("Double clicked") -- put logic here

        else
            lastClick  = tick() -- set last click when not short enough time
        end
    end
end)
#

if you want i can make it so it does not show the cursor thing

#

so it doesn't look like its clickable

sour plaza
#

so do i replace that script with the other

#

and can you make that it turns the clickable cursor into a custom decal?

#

would be fire

fringe crown
fringe crown
sour plaza
#

k

#

the world needs more peoples like you, most of the peoples just say: Learn scripting then even if im learning scripting by askin when i get something wrong

fringe crown
#

my main thing is whenever someone asks for help i teach them (comments)

#

so if you want to learn you can by reading the comments

sour plaza
#

um

#

how do i scale the cursor down-

sour plaza
fringe crown
#

one sec

#

idk for either of those

#

i need to go now

#

hope you find help

sour plaza
#

nvm i found tutorial

fringe crown
#

also im gonna keep track of every person i help with and put ot all in a uncopylocked place

sour plaza
#

tell me when u release it

sour plaza
# fringe crown one sec

nvm, the one on the tutorial overwrites the one when hovered over the double click one and im goin to sleep now, maybe u can give me a script on how to change the cursor image but that it doest overwrite the hover one so you still get the other cursor when hovering

fringe crown
#

i need a break and i prob wont be able to find a simple solution to the cursor thing