Advertisement
Cat_in_the_hat

A tree that is able to be cut down

Jun 21st, 2025 (edited)
374
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.82 KB | Gaming | 0 0
  1. local spacing = 12
  2. local treeSpots = {}
  3. local placedTrees = {}
  4. local requiredHits = 6
  5. local spreadat = ItemType.GRASS
  6.  
  7. local function isFarEnough(pos)
  8.     for _, placedPos in pairs(placedTrees) do
  9.         if (placedPos - pos).Magnitude < spacing then
  10.             return false
  11.         end
  12.     end
  13.     return true
  14. end
  15.  
  16. for _, block in pairs(BlockService.getAllBlocks({ spreadat })) do
  17.     local basePos = block.position
  18.     if isFarEnough(basePos) then
  19.         table.insert(treeSpots, basePos)
  20.         table.insert(placedTrees, basePos)
  21.     end
  22. end
  23.  
  24. for _, basePos in pairs(treeSpots) do
  25.     local trunk = {}
  26.     local leaves = {}
  27.     local allParts = {}
  28.     local partData = {}
  29.     local hits = 0
  30.  
  31.     for i = 1, 6 do
  32.         local part = PartService.createPart(ItemType.WOOL_BROWN, basePos + Vector3.new(0, i * 3, 0))
  33.         part:setSize(Vector3.new(3, 3, 3))
  34.         part:setAnchored(true)
  35.         part:setCollidable(true)
  36.         table.insert(trunk, part)
  37.     end
  38.  
  39.     local center = basePos + Vector3.new(0, 21, 0)
  40.     for x = -2, 2 do
  41.         for y = -2, 2 do
  42.             for z = -2, 2 do
  43.                 local offset = Vector3.new(x, y, z)
  44.                 if offset.Magnitude <= 2.5 then
  45.                     local pos = center + offset * 3
  46.                     local part = PartService.createPart(ItemType.WOOL_GREEN, pos)
  47.                     part:setSize(Vector3.new(3, 3, 3))
  48.                     part:setAnchored(true)
  49.                     part:setCollidable(true)
  50.                     table.insert(leaves, part)
  51.                 end
  52.             end
  53.         end
  54.     end
  55.  
  56.     for _, part in pairs(trunk) do table.insert(allParts, part) end
  57.     for _, part in pairs(leaves) do table.insert(allParts, part) end
  58.     for _, part in pairs(allParts) do
  59.         table.insert(partData, {
  60.             part = part,
  61.             offset = part:getPosition() - basePos
  62.         })
  63.     end
  64.  
  65.     Events.WeaponSwing(function(event)
  66.         local entity = event.player:getEntity()
  67.         if not entity then return end
  68.         if (entity:getPosition() - basePos - Vector3.new(0, 3, 0)).Magnitude > 7 then return end
  69.  
  70.         hits += 1
  71.         if hits == requiredHits then
  72.             local direction = entity:getCFrame().LookVector
  73.             local fallAxis = Vector3.new(0, 1, 0):Cross(direction).Unit
  74.  
  75.             task.spawn(function()
  76.                 for i = 1, 20 do
  77.                     task.wait(0.005)
  78.                     local progress = i / 20
  79.                     local rotation = CFrame.fromAxisAngle(fallAxis, math.rad(70) * progress)
  80.                     for _, data in pairs(partData) do
  81.                         local rotated = rotation:vectorToWorldSpace(data.offset)
  82.                         data.part:setCFrame(CFrame.new(basePos + rotated) * rotation)
  83.                     end
  84.                 end
  85.  
  86.                 for _, data in pairs(partData) do
  87.                     data.part:setAnchored(false)
  88.                     data.part:setCollidable(true)
  89.                 end
  90.  
  91.                 task.delay(7, function()
  92.                     local index = 1
  93.                     local batchSize = 1
  94.                     while index <= #partData do
  95.                         for i = index, math.min(index + batchSize - 1, #partData) do
  96.                             partData[i].part:setCollidable(false)
  97.                         end
  98.                         task.wait(0.2)
  99.                         index += batchSize
  100.                         if batchSize < 4 then
  101.                             batchSize += 1
  102.                         end
  103.                     end
  104.                 end)
  105.             end)
  106.         end
  107.     end)
  108. end
Advertisement
Comments
  • Cat_in_the_hat
    3 hours
    1. Showcase of code is here : https://discord.com/channels/1132704840313749615/1386169971645616189/1386170355218911272
    2. It's a script that's makes a tree modle on a random spot on spread at and keep placing trees with gaps placement like forest and now when a player swings there sword at the tree it fall down and Breck and the tree parts will be fall in floor and be destroyed  after 7 seconds for there won't be lag
Add Comment
Please, Sign In to add comment
Advertisement