Advertisement
HowToRoblox

AxeServer

Jul 21st, 2022
2,596
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.59 KB | None | 0 0
  1. local re = game.ReplicatedStorage:WaitForChild("AxeRE")
  2.  
  3. local cooldown = {}
  4.  
  5.  
  6. re.OnServerEvent:Connect(function(player, target, mouseHit)
  7.    
  8.     if not cooldown[player] and player.Character and target and target.Name == "Trunk" and target:FindFirstChild("Health") and mouseHit then
  9.        
  10.         local hrp = player.Character.HumanoidRootPart
  11.         local distance = (hrp.Position - target.Position).Magnitude
  12.        
  13.         if distance <= 5 then
  14.             cooldown[player] = true
  15.            
  16.             if not target:FindFirstChild("MaxHealth") then
  17.                 local maxHealth = Instance.new("IntValue")
  18.                 maxHealth.Name = "MaxHealth"
  19.                 maxHealth.Value = target.Health.Value
  20.                 maxHealth.Parent = target
  21.             end
  22.            
  23.             target.Health.Value -= 1
  24.            
  25.             if target.Health.Value < 1 then
  26.            
  27.                 local treeBottom = target.CFrame:ToWorldSpace(CFrame.new(Vector3.new(0, -target.Size.Y/2, 0)))
  28.                 local treeTop = target.CFrame:ToWorldSpace(CFrame.new(Vector3.new(0, target.Size.Y/2, 0)))
  29.  
  30.                 local yHeight = target.CFrame:PointToObjectSpace(mouseHit.Position).Y + target.Size.Y/2
  31.  
  32.                 local treeMiddle = treeBottom:PointToWorldSpace(Vector3.new(0, yHeight, 0))
  33.  
  34.                 local bottomSize = (treeMiddle - treeBottom.Position).Magnitude
  35.                 local topSize = (treeMiddle - treeTop.Position).Magnitude
  36.  
  37.                 local bottomPos = treeBottom:PointToWorldSpace(Vector3.new(0, bottomSize/2, 0))
  38.                 local topPos = treeTop:PointToWorldSpace(Vector3.new(0, -topSize/2, 0))
  39.                
  40.                 target.Health:Destroy()
  41.                
  42.                 local bottomPart = target:Clone()
  43.                 bottomPart.Position = bottomPos
  44.                 bottomPart.Size = Vector3.new(target.Size.X, bottomSize, target.Size.Z)
  45.                 bottomPart.Parent = workspace
  46.  
  47.                 local topPart = target:Clone()
  48.                 topPart.Position = topPos
  49.                 topPart.Size = Vector3.new(target.Size.X, topSize, target.Size.Z)
  50.                 topPart.Anchored = false
  51.                 topPart.Parent = workspace
  52.                
  53.                 local bv = Instance.new("BodyVelocity")
  54.                 bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
  55.                 bv.Velocity = player.Character.HumanoidRootPart.CFrame.LookVector
  56.                 bv.Parent = topPart
  57.                 game:GetService("Debris"):AddItem(bv, 1)
  58.                
  59.                 local newHealthValue = target.MaxHealth:Clone()
  60.                 newHealthValue.Name = "Health"
  61.                 newHealthValue.Parent = bottomPart
  62.                 newHealthValue:Clone().Parent = topPart
  63.                
  64.                 if target.Parent:FindFirstChild("Leaves") then
  65.                     local leaves = target.Parent.Leaves
  66.                     spawn(function()
  67.                         leaves.CanCollide = false
  68.                         leaves.Anchored = false
  69.                         wait(1)
  70.                         leaves.Parent:Destroy()
  71.                     end)
  72.                 end
  73.                
  74.                 target:Destroy()
  75.             end
  76.            
  77.             wait(1)
  78.             cooldown[player] = false
  79.         end
  80.     end
  81. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement