I made a script to break down street lights.
I want to make it break only in the event of a car crash. It breaks even if it collides with a person, how can I fix it?
local regentime = 10
local model = script.Parent
local destroyed = false
for i,block in ipairs(model:GetChildren()) do
if block:IsA("BasePart") then
block.Touched:Connect(function(touch)
if touch.Anchored or destroyed then return end
destroyed = true
for i,block in ipairs(model:GetChildren()) do
if block:IsA("BasePart") then
local clone = block:Clone()
clone.Parent = workspace
clone.Anchored = false
block.Transparency = 1
block.CanCollide = false
coroutine.resume(coroutine.create(function()
wait(regentime)
clone:Destroy()
block.Transparency = 0
block.CanCollide = true
end))
end
end
wait(regentime)
destroyed = false
end)
end
end