Advertisement
Quoteory

Untitled

Aug 5th, 2019
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.92 KB | None | 0 0
  1. local center = workspace.Center
  2. local partToCheck = workspace.CheckPart
  3.  
  4. local minY, maxY = -10, 15 -- parts should be able to go down more than up
  5. local distance = 24 -- the max distance a part can be from the center position (on x and z axis)
  6. local centerPos = center.Position
  7.  
  8.  
  9.  
  10. function isInBounds(part)
  11.     local partPos = part.Position
  12.    
  13.     local xDist = (partPos.X - centerPos.X)
  14.     local zDist = (partPos.Z - centerPos.Z)
  15.     local yDist = (partPos.Y - centerPos.Y)
  16.    
  17.     local withinY = yDist < maxY and yDist > minY
  18.     -- checks if the parts y is less than the max, and greater than the min
  19.    
  20.     local withinXZ = math.abs(xDist) < distance and math.abs(zDist) < distance
  21.     -- checks if the parts x and z are not further away than the distance
  22.    
  23.     if withinXZ and withinY then
  24.         part.BrickColor = BrickColor.Green()
  25.     else
  26.         part.BrickColor = BrickColor.Red()
  27.     end
  28.    
  29. end
  30.  
  31. while true do
  32.     isInBounds(partToCheck)
  33.     wait()
  34. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement