Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local spacing = 12
- local treeSpots = {}
- local placedTrees = {}
- local requiredHits = 6
- local spreadat = ItemType.GRASS
- local function isFarEnough(pos)
- for _, placedPos in pairs(placedTrees) do
- if (placedPos - pos).Magnitude < spacing then
- return false
- end
- end
- return true
- end
- for _, block in pairs(BlockService.getAllBlocks({ spreadat })) do
- local basePos = block.position
- if isFarEnough(basePos) then
- table.insert(treeSpots, basePos)
- table.insert(placedTrees, basePos)
- end
- end
- for _, basePos in pairs(treeSpots) do
- local trunk = {}
- local leaves = {}
- local allParts = {}
- local partData = {}
- local hits = 0
- for i = 1, 6 do
- local part = PartService.createPart(ItemType.WOOL_BROWN, basePos + Vector3.new(0, i * 3, 0))
- part:setSize(Vector3.new(3, 3, 3))
- part:setAnchored(true)
- part:setCollidable(true)
- table.insert(trunk, part)
- end
- local center = basePos + Vector3.new(0, 21, 0)
- for x = -2, 2 do
- for y = -2, 2 do
- for z = -2, 2 do
- local offset = Vector3.new(x, y, z)
- if offset.Magnitude <= 2.5 then
- local pos = center + offset * 3
- local part = PartService.createPart(ItemType.WOOL_GREEN, pos)
- part:setSize(Vector3.new(3, 3, 3))
- part:setAnchored(true)
- part:setCollidable(true)
- table.insert(leaves, part)
- end
- end
- end
- end
- for _, part in pairs(trunk) do table.insert(allParts, part) end
- for _, part in pairs(leaves) do table.insert(allParts, part) end
- for _, part in pairs(allParts) do
- table.insert(partData, {
- part = part,
- offset = part:getPosition() - basePos
- })
- end
- Events.WeaponSwing(function(event)
- local entity = event.player:getEntity()
- if not entity then return end
- if (entity:getPosition() - basePos - Vector3.new(0, 3, 0)).Magnitude > 7 then return end
- hits += 1
- if hits == requiredHits then
- local direction = entity:getCFrame().LookVector
- local fallAxis = Vector3.new(0, 1, 0):Cross(direction).Unit
- task.spawn(function()
- for i = 1, 20 do
- task.wait(0.005)
- local progress = i / 20
- local rotation = CFrame.fromAxisAngle(fallAxis, math.rad(70) * progress)
- for _, data in pairs(partData) do
- local rotated = rotation:vectorToWorldSpace(data.offset)
- data.part:setCFrame(CFrame.new(basePos + rotated) * rotation)
- end
- end
- for _, data in pairs(partData) do
- data.part:setAnchored(false)
- data.part:setCollidable(true)
- end
- task.delay(7, function()
- local index = 1
- local batchSize = 1
- while index <= #partData do
- for i = index, math.min(index + batchSize - 1, #partData) do
- partData[i].part:setCollidable(false)
- end
- task.wait(0.2)
- index += batchSize
- if batchSize < 4 then
- batchSize += 1
- end
- end
- end)
- end)
- end
- end)
- end
Advertisement
Comments
-
- Showcase of code is here : https://discord.com/channels/1132704840313749615/1386169971645616189/1386170355218911272
- 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