Chronomad

Destructible Props

Feb 28th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. B = script.Parent F = script.Parent
  2. local prop = game.ServerStorage.Props.Breakables.brokenBarrel --Broken Version of prop
  3.  
  4. script.Parent.Healthy.Changed:connect(function(health)
  5. if script.Parent.Healthy.Value < 1 then --if props health is reduced to 0
  6. local x = prop:Clone() x.Parent = game.Workspace x:SetPrimaryPartCFrame(script.Parent.BarrelCore.CFrame)
  7. --replace prop with broken version
  8. x:BreakJoints() B:Destroy() F = x --remove old version and destroy welds on broken version
  9.  
  10.  
  11. for C, D in pairs(x:GetChildren()) do D.CollisionGroupId = 1 --prevent player from colliding with debris
  12.  
  13. local bp = Instance.new("BodyThrust") -- sends debris flying in random directions
  14. bp.Parent = D
  15. bp.Force = Vector3.new (math.random(-3000,3000),math.random(-3000,3000),math.random(-3000,3000));
  16. wait(.001)
  17. bp:Destroy()
  18.  
  19. end
  20. for C, D in pairs(F:GetChildren()) do
  21. wait(.1)
  22. game:GetService("Debris"):AddItem(D, .13) -- clean up debris
  23. end
  24. end end)
  25.  
  26.  
  27.  
  28. script.Parent.hitReceptor.Changed:connect(function(hit) --ability to take damage
  29. if script.Parent.hitReceptor.Value == true then wait(.4) script.Parent.hitReceptor.Value = false
  30. --end
  31. end end)
Advertisement
Add Comment
Please, Sign In to add comment