Advertisement
Cat_in_the_hat

Claim blocks thing

Aug 25th, 2024
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.66 KB | None | 0 0
  1. local playerBlocksPositions = {}
  2.  
  3. local pickPositions = {
  4.     Vector3.new(348, 66, 315),
  5.     Vector3.new(342, 66, 315),
  6.     Vector3.new(339, 66, 312),
  7.     Vector3.new(345, 66, 312),
  8.     Vector3.new(351, 66, 312),
  9.     Vector3.new(348, 66, 309),
  10.     Vector3.new(342, 66, 309),
  11.     Vector3.new(351, 66, 306),
  12.     Vector3.new(345, 66, 306),
  13.     Vector3.new(339, 66, 306)
  14. }
  15.  
  16. Events.BlockPlace(function(event)
  17.     local player = event.player
  18.     local position = event.position
  19.     local blockType = event.blockType
  20.  
  21.     if not playerBlocksPositions[player.userId] then
  22.         playerBlocksPositions[player.userId] = {}
  23.     end
  24.  
  25.     table.insert(playerBlocksPositions[player.userId], {position = position, blockType = blockType})
  26. end)
  27.  
  28. local function destroyPlayerBlocks(player)
  29.     if playerBlocksPositions[player.userId] then
  30.         for _, blockInfo in pairs(playerBlocksPositions[player.userId]) do
  31.             BlockService.destroyBlock(blockInfo.position)
  32.         end
  33.         playerBlocksPositions[player.userId] = nil
  34.     end
  35. end
  36.  
  37. local function placeBlockAtRandomPosition()
  38.     if #pickPositions == 0 then return end
  39.  
  40.     local randomIndex = math.random(1, #pickPositions)
  41.     local position = table.remove(pickPositions, randomIndex)
  42.  
  43.     BlockService.placeBlock(ItemType.CLAY_RED, position)
  44.  
  45.     return position
  46. end
  47.  
  48. local function checkNearbyEntitiesAbove(position)
  49.     local checkPosition = position + Vector3.new(0, 5, 0)
  50.     local nearbyPlayers = PlayerService.getNearbyPlayers(checkPosition, 3)
  51.  
  52.     if nearbyPlayers then
  53.         for _, player in pairs(nearbyPlayers) do
  54.             local entity = player:getEntity()
  55.             if entity then
  56.                 local entityPos = entity:getPosition()
  57.                 if entityPos and (entityPos - checkPosition).Magnitude <= 3 then
  58.                     return player
  59.                 end
  60.             end
  61.         end
  62.     end
  63.  
  64.     return nil
  65. end
  66.  
  67. local function startBlockPlacingRoutine()
  68.     while #pickPositions > 0 do
  69.         local position = placeBlockAtRandomPosition()
  70.  
  71.         while true do
  72.             task.wait(0.01)
  73.  
  74.             local player = checkNearbyEntitiesAbove(position)
  75.  
  76.             if player then
  77.                 BlockService.destroyBlock(position)
  78.                 BlockService.placeBlock(ItemType.CLAY_GREEN, position)
  79.                 destroyPlayerBlocks(player)
  80.                 break
  81.             end
  82.         end
  83.     end
  84. end
  85.  
  86. Events.EntityDeath(function(event)
  87.     local player = event.entity:getPlayer()
  88.     if player then
  89.         if event.finalKill then
  90.             destroyPlayerBlocks(player)
  91.         end
  92.     end
  93. end)
  94.  
  95. task.spawn(startBlockPlacingRoutine)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement