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
for some reason scripting helpers wont let me use answer so ill do it here you can do wait(amount of seconds) part:Destroy()
thank you so much omg
ill put it in answer when scripting helpers isn't broken
ok i added an answer plz mark it as answer
try and use the script here
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).
ok i will thank you
ok so the thing is i added the code but it did nothing and the script wasnt even broken