Advertisement
Cat_in_the_hat

Team door

Oct 1st, 2024
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.79 KB | None | 0 0
  1. local teamDoorPosition = Vector3.new(321, 66, 339)
  2. local blockSize = Vector3.new(3, 3, 3)
  3. local gap = 3
  4. local xSideBlocks = 0
  5. local zSideBlocks = 2
  6. local blocksTall = 5
  7. local checkCooldown = -9999999
  8. local findRadius = 5
  9.  
  10. local enableTeam = "Blue"
  11. local offsetsX = {0}
  12. local offsetsZ = {0}
  13.  
  14. for i = 1, xSideBlocks do
  15.     table.insert(offsetsX, -i * gap)
  16.     table.insert(offsetsX, i * gap)
  17. end
  18. for j = 1, zSideBlocks do
  19.     table.insert(offsetsZ, -j * gap)
  20.     table.insert(offsetsZ, j * gap)
  21. end
  22.  
  23. local function createPart(position, collidable)
  24.     local partType = ItemType["WOOL_" .. enableTeam:upper()]
  25.     local part = PartService.createPart(partType, position)
  26.     part:setSize(blockSize)
  27.     part:setAnchored(true)
  28.     part:setCollidable(collidable)
  29.     part:setTransparency(0.8)
  30.  
  31.     local currentCollidable = collidable
  32.  
  33.     task.spawn(function()
  34.         while true do
  35.             task.wait(checkCooldown)
  36.  
  37.             local nearbyEntities = EntityService.getNearbyEntities(part:getPosition(), findRadius)
  38.             local foundNotBlue = false
  39.             local foundTeam = false
  40.  
  41.             if nearbyEntities then
  42.                 for _, entity in ipairs(nearbyEntities) do
  43.                     if entity:isAlive() then
  44.                         local player = entity:getPlayer()
  45.                         if player then
  46.                             local team = TeamService.getTeam(player)
  47.                             if team.name ~= enableTeam then
  48.                                 foundNotBlue = true
  49.                                 local knockback = {
  50.                                     fromPosition = part:getPosition(),
  51.                                     horizontal = 0.4,
  52.                                     vertical = 0.4
  53.                                 }
  54.                                 CombatService.damage(entity, 0, nil, knockback)
  55.                             else
  56.                                 foundTeam = true
  57.                             end
  58.                         end
  59.                     end
  60.                 end
  61.             end
  62.  
  63.             if foundNotBlue and not currentCollidable then
  64.                 part:destroy()
  65.                 createPart(part:getPosition(), true)
  66.                 break
  67.             elseif foundTeam and currentCollidable then
  68.                 part:destroy()
  69.                 createPart(part:getPosition(), false)
  70.                 break
  71.             end
  72.         end
  73.     end)
  74.  
  75.     return part
  76. end
  77.  
  78. local parts = {}
  79.  
  80. for layer = 0, blocksTall - 1 do
  81.     local yOffset = layer * gap
  82.  
  83.     for i = 1, #offsetsX do
  84.         for j = 1, #offsetsZ do
  85.             local positionX = teamDoorPosition + Vector3.new(offsetsX[i], yOffset, offsetsZ[j])
  86.             table.insert(parts, createPart(positionX, false))
  87.         end
  88.     end
  89. end
Tags: bedwars
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement