Tnt something
if it gets hit hard enough like from gmod it explodes
i tried making something myself, and it worked somewhat, but is not too great and if put on any sort of conveyor or “cannon” it explodes immediately
-- Segment of the code
function Hit(Velocity)
local Resistance = SelfMass/5 * Explosive
local X = if Velocity.X > MinVelocity then Velocity.X else 0
local Y = if Velocity.Y > MinVelocity then Velocity.Y else 0
local Z = if Velocity.Z > MinVelocity then Velocity.Z else 0
local Damage = (X+Y+Z) * SelfMass
if Damage > Resistance then
TakeDamage((Damage - Resistance)/10)
end
end
function GotHit(Velocity, Mass)
local Resistance = SelfMass/5 * Explosive
local X = if Velocity.X > MinVelocity then Velocity.X else 0
local Y = if Velocity.Y > MinVelocity then Velocity.Y else 0
local Z = if Velocity.Z > MinVelocity then Velocity.Z else 0
local Damage = (X+Y+Z) * Mass
if Damage > Resistance then
TakeDamage((Damage - Resistance)/10)
end
end
script.Parent.Touched:Connect(function(TouchedPart)
if HasExploded then return end
local Velocity = script.Parent.AssemblyLinearVelocity
local Velocity2 = if TouchedPart:IsA("Part") then TouchedPart.AssemblyLinearVelocity else Velocity
print(Velocity)
if Velocity.X > MinVelocity or Velocity.Y > MinVelocity or Velocity.Z > MinVelocity then
Hit(Velocity)
end
if Velocity2.X > MinVelocity or Velocity2.Y > MinVelocity or Velocity.Z > MinVelocity then
if not TouchedPart.Anchored then GotHit(Velocity2, TouchedPart.Mass) end
end
end)
Full Code
local HasExploded = false
local MinVelocity = 10
local Explosive = 300
local SelfMass = script.Parent.Mass
local TntHumanoid = script.Parent.TntHumanoid
local Fire = script.Parent.TntFire
local Smoke = script.Parent.Smoke
function Explode()
HasExploded = true
local Explosion = Instance.new("Explosion")
Explosion.Parent = workspace
Explosion.Position = script.Parent.Position
script.Parent:Destroy()
end
function TakeDamage(Num)
print("Took Damage: " .. Num)
TntHumanoid:TakeDamage(Num)
end
function Damaged()
if HasExploded then return end
local Health = TntHumanoid.Health
if Health == TntHumanoid.MaxHealth then
Fire.Enabled = false
Smoke.Enabled = false
elseif Health > TntHumanoid.MaxHealth * 2 / 3 then
Fire.Enabled = true
Fire.Heat = 4
Fire.Size = 7
Smoke.Enabled = false
elseif Health > TntHumanoid.MaxHealth * 1 / 3 then
Fire.Heat = 5
Fire.Size = 8
Smoke.Enabled = false
elseif Health > 0 then
if not Fire.Enabled then
Fire.Enabled = true
Fire.Heat = 5
Fire.Size = 8
end
Smoke.Enabled = true
Smoke.Opacity = 0.1
Smoke.RiseVelocity = 0
Smoke.Size = 0.1
Smoke.TimeScale = 1
elseif Health <= 0 then
Explode()
end
end
function Hit(Velocity)
local Resistance = SelfMass/5 * Explosive
local X = if Velocity.X > MinVelocity then Velocity.X else 0
local Y = if Velocity.Y > MinVelocity then Velocity.Y else 0
local Z = if Velocity.Z > MinVelocity then Velocity.Z else 0
local Damage = (X+Y+Z) * SelfMass
if Damage > Resistance then
TakeDamage((Damage - Resistance)/10)
end
end
function GotHit(Velocity, Mass)
local Resistance = SelfMass/5 * Explosive
local X = if Velocity.X > MinVelocity then Velocity.X else 0
local Y = if Velocity.Y > MinVelocity then Velocity.Y else 0
local Z = if Velocity.Z > MinVelocity then Velocity.Z else 0
local Damage = (X+Y+Z) * Mass
if Damage > Resistance then
TakeDamage((Damage - Resistance)/10)
end
end
script.Parent.Touched:Connect(function(TouchedPart)
if HasExploded then return end
local Velocity = script.Parent.AssemblyLinearVelocity
local Velocity2 = if TouchedPart:IsA("Part") then TouchedPart.AssemblyLinearVelocity else Velocity
print(Velocity)
if Velocity.X > MinVelocity or Velocity.Y > MinVelocity or Velocity.Z > MinVelocity then
Hit(Velocity)
end
if Velocity2.X > MinVelocity or Velocity2.Y > MinVelocity or Velocity.Z > MinVelocity then
if not TouchedPart.Anchored then GotHit(Velocity2, TouchedPart.Mass) end
end
end)
TntHumanoid:GetPropertyChangedSignal("Health"):Connect(Damaged)