Hello devforum members! I am new to scripting and need help with something. I want to make a script that deletes parts 5 or so seconds after being hit by an explosion. Any help is appreciated. Thank you!
I recommend using game.Debris:AddItem(part,numberofsecondsofdelay)
You could use this in a script as such:
part.Touched:Connect(function()
game.Debris:AddItem(part,3)
end)
I will try this. Thanks for the feedback.
Use the built-in ‘Explosion’ class and its ‘Hit’ event/signal.
https://developer.roblox.com/en-us/api-reference/class/Explosion
local Game = game
local Workspace = workspace
local Debris = Game:GetService("Debris")
local function OnHit(HitPart, HitDistance)
Debris:AddItem(HitPart, 5) --Remove part 5 seconds after being hit.
end
local Explosion = Instance.new("Explosion")
Explosion.Position = Vector3.new(0, 0, 0) --Desired position of explosion.
Explosion.Hit:Connect(OnHit)
Explosion.Parent = Workspace