local blockWidth = 5
local blockHeight = 5
local gridWidth = 8
local gridHeight = 20
local blockSpeed = 0.1
local spawnDelay = 3
local function createBlock(scriptEnabled)
local block = game.ServerStorage.Part:Clone()
block.Parent = game.Workspace
block.Anchored = true
block.CanCollide = true
local spawnX = math.random(1, gridWidth - 1) * blockWidth
local spawnY = gridHeight * blockHeight
local spawnZ = 0
block.Position = Vector3.new(spawnX, spawnY, spawnZ)
while true do
if block.Position.Y - blockHeight/2 <= 0 or block.Parent == nil then
break
end
block.Position = block.Position - Vector3.new(0, blockHeight, 0)
wait(blockSpeed)
local nearbyParts = workspace:FindPartsInRegion3(
Region3.new(block.Position - Vector3.new(blockWidth/2, blockHeight/2, blockWidth/2),
block.Position + Vector3.new(blockWidth/2, blockHeight/2, blockWidth/2)),
nil, -- Ignore list
10 -- MaxParts
)
local collided = false
for _, nearbyPart in pairs(nearbyParts) do
if nearbyPart ~= block and nearbyPart.CanCollide then
local topOfNearbyPart = nearbyPart.Position.Y + nearbyPart.Size.Y/2
local bottomOfBlock = block.Position.Y - blockHeight/2
local isLandingSpot = math.abs(topOfNearbyPart - bottomOfBlock - 0.05) < 0.01 or math.abs(nearbyPart.Position.X - block.Position.X) < blockWidth/2
if nearbyPart == game.Workspace.Baseplate or (isLandingSpot and blockHeight <= 10) then
collided = true
break
end
end
end
if collided then
block.Anchored = true
break
end
end
-- Create a new block
createBlock(scriptEnabled)
end
while true do
createBlock(true) -- pass in true to indicate script is enabled
wait(spawnDelay)
end
local blockWidth = 10
local blockHeight = 10
local gridWidth = 8
local gridHeight = 20
local blockSpeed = 0.1
local spawnDelay = 3
local function createBlock(scriptEnabled)
local block = game.ServerStorage.Part:Clone()
block.Parent = game.Workspace
block.Anchored = true
block.CanCollide = true
local spawnX = math.random(1, gridWidth - 1) * blockWidth
local spawnY = gridHeight * blockHeight
local spawnZ = 0
block.Position = Vector3.new(spawnX, spawnY, spawnZ)
while true do
if block.Position.Y - blockHeight/2 <= 0 or block.Parent == nil then
break
end
local stackHeight = 0
local currentBlock = block
while currentBlock.Parent ~= nil do
stackHeight = stackHeight + 1
currentBlock = currentBlock.Parent
end
if stackHeight >= 10 then
block.Anchored = true
break
end
block.Position = block.Position - Vector3.new(0, blockHeight, 0)
wait(blockSpeed)
local nearbyParts = workspace:FindPartsInRegion3(
Region3.new(block.Position - Vector3.new(blockWidth/2, blockHeight/2, blockWidth/2),
block.Position + Vector3.new(blockWidth/2, blockHeight/2, blockWidth/2)),
nil, -- Ignore list
10 -- MaxParts
)
local collided = false
for _, nearbyPart in pairs(nearbyParts) do
if nearbyPart ~= block and nearbyPart.CanCollide then
local topOfNearbyPart = nearbyPart.Position.Y + nearbyPart.Size.Y/2
local bottomOfBlock = block.Position.Y - blockHeight/2
local isLandingSpot = math.abs(topOfNearbyPart - bottomOfBlock - 0.05) < 0.01 or math.abs(nearbyPart.Position.X - block.Position.X) < blockWidth/2
if nearbyPart == game.Workspace.Floor or (isLandingSpot and blockHeight <= 10) then
collided = true
break
end
end
end
if collided then
block.Anchored = true
break
end
end
-- Create a new block
createBlock(scriptEnabled)
end
while true do
createBlock(true) -- pass in true to indicate script is enabled
wait(spawnDelay)
end
You can also just use math.floor (or math.ceil, floor is usually used instead though) to get rid of those long pesky decimals like this:
local decimal_places = 100
-- evil floating point precision error
-- if theres enough 9's in "x", it will start rounding up instead of down
local x = 5.43999999999999999999999999999999999999999
print(math.floor(x * decimal_places) / decimal_places) -- 5.44