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

How can i add a cooldown and destroy to this script?

So i have this script that spawns a part when 'e' is pressed but i want to know how cna i make it so the part destroys after a few seconds and then the script is on cooldown

local Player = game.Players.LocalPlayer

local Mouse = Player:GetMouse()

Mouse.KeyDown:connect(function(Key) Key = Key:lower() if Key == 'e' then print'e' local Part = Instance.new('Part', game.Workspace) Part.Anchored = true Part.CFrame = Player.Character.Head.CFrame * CFrame.new(0,0,-5) end end)

https://www.youtube.com/watch?v=mHDarhgxvNg here is a video of what the script does, i want to make it so when you press it once it goes on cool down and after 5 seconds the part destroys

8 comments

0

for some reason scripting helpers wont let me use answer so ill do it here you can do wait(amount of seconds) part:Destroy()

0

thank you so much omg

0

ill put it in answer when scripting helpers isn't broken

0

ok i added an answer plz mark it as answer

0

try and use the script here

0

Even though botw_legend answered your question, you should also look into game:GetService("Debris"), it's similar but more efficient (as said by many).

0

ok i will thank you

0

ok so the thing is i added the code but it did nothing and the script wasnt even broken

2 answers

Heyyy you could do (this is an Example)

Instance.new(“Part”)
local Part = game.Workspace.Part

wait(1)
Part:Destroy()


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