so i tried working with a coroutine and i am calling it multiple times per second which i know is the issue but i am not sure how to fix it and this is vital to my game because as the script clearly says i am trying to delete the parts after 10 seconds but it is part of the game to call this function multiple times with short intervals, if someone could help me with this it would be great
Script:
local Event = game.ReplicatedStorage.Break
local Debounce = false
local Timer = coroutine.wrap(function(part)
wait(10)
part:Destroy()
end)
Event.OnServerEvent:Connect(function(Player,hit)
-- print(hit,hit:GetFullName())
if hit.Parent == workspace and hit.Name == "DestPart" then
if Debounce == false then
Debounce = true
hit.Anchored = false
Timer(hit)
-- wait(10)
-- hit:Destroy()
Debounce = false
end
elseif hit.Parent:IsA("Model") and hit.Name == "DestPart" then
if Debounce == false then
Debounce = true
for i, v in pairs(hit.Parent:GetDescendants()) do
if v:IsA("Part") or v:IsA("MeshPart") or v:IsA("UnionOperation") then
v.Anchored = false
Timer(v)
-- local ex = Instance.new("Explosion")
-- ex.Parent = v
-- ex.Position = v.Position
-- ex.Visible = false
-- ex.BlastPressure = 50
-- ex.DestroyJointRadiusPercent = 0
-- ex.ExplosionType = "NoCraters"
-- wait(10)
-- v:Destroy()
end
end
Debounce = false
end
end
end)

1 comment
sweet thank you