Hey there, im trying to make an exploding barrel that will take damage or explode based on velocity
local function OnTouchy()
local velo = script.Parent.Velocity
if velo <= Vector3(30,30,30) or script.Parent.Parent.Humanoid.Health < 60 then
local explode = Instance.new("Explosion")
explode.Position = script.Parent
explode.BlastRadius = 60
explode.BlastPressure = 3000
for i = 1, 30 do
local Debris = game:GetService("Debris")
local Part = Instance.new("Part")
Part.Size = Vector3.new(math.random(0.25,1),math.random(0.25,1),math.random(0.25,1))
Part.Parent = script.Parent
Part.Position = script.Parent.Position
Part.CanCollide = true
Part.Velocity = Vector3.new(math.random(0.25,30),math.random(0.25,70),math.random(0.25,68))
Debris:AddItem(Part, 7)
end
script.Explosion6:Play()
script.Parent.Parent:Destroy()
end
end
script.Parent.Touched:Connect(OnTouchy)
yes i know this code is incredible innefficient, im new to roblox lua
