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

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

Asked by 4 years ago
Edited 4 years ago

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

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() botw_legend 502 — 4y
0
thank you so much omg Funnyskyswagway3 30 — 4y
0
ill put it in answer when scripting helpers isn't broken botw_legend 502 — 4y
0
ok i added an answer plz mark it as answer botw_legend 502 — 4y
View all comments (4 more)
0
try and use the script here Funnyskyswagway3 30 — 4y
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). Player1_Joined 271 — 4y
0
ok i will thank you Funnyskyswagway3 30 — 4y
0
ok so the thing is i added the code but it did nothing and the script wasnt even broken Funnyskyswagway3 30 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

you can do

wait(amount of seconds) 
part:Destroy()
Ad
Log in to vote
0
Answered by
iivSnooxy 248 Moderation Voter
4 years ago

Heyyy you could do (this is an Example)

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

wait(1)
Part:Destroy()


Answer this question