Advertisement
TGazza

Roblox Part-Model Cloaner with Spawn check

Jul 9th, 2020
1,760
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.41 KB | None | 0 0
  1. --[[
  2. ##############################################################################################################
  3. ################### Script Made By TGazza ######################## Model Cloner with overlap check v1.0 ######
  4. ##############################################################################################################
  5. ]]
  6.  
  7. --// name of your model or part you want to clone
  8. local Model_Or_Part_Name = "Observation Tower"
  9. local deBug = false --// change this to true to see a message in the output
  10. local CloneMETime = 5 --// in seconds!
  11.  
  12. --[[
  13. ##############################################################################################################
  14. #################### Don't change anything below this unless you know what your are doing!####################
  15. ##############################################################################################################
  16. ]]
  17.  
  18. local model = (function()
  19.     local Chk = script.Parent:FindFirstChild(Model_Or_Part_Name)
  20.     if(Chk == nil) then
  21.         error("Error: Model_Or_Part_Name Varable is not set\n replace [\" Model_Or_Part_Name \"] With the name of the model or part you want to clone on Line 8 and try again!")
  22.     end
  23.     return Chk
  24.  end)()
  25.  
  26. local Cpy = model:Clone()
  27.  
  28. local ModelPosition,ModelSize = (function()
  29.     local isModel = model:IsA("Model")
  30.     if(isModel == true) then
  31.         local Bonding_BoxCFrame, Bonding_Box = model:GetBoundingBox()
  32.         return Bonding_BoxCFrame.Position,Bonding_Box
  33.     else
  34.         return model.Position, model.Size
  35.     end
  36. end)()
  37.  
  38. local function isAreaEmpty()
  39.     --// the following code is taken from the roblox wiki
  40.     --// https://developer.roblox.com/en-us/api-reference/function/WorldRoot/FindPartsInRegion3
  41.     --// Just modified to work with models and Parts
  42.     local SA = ModelPosition - (0.5 * (ModelSize*0.95))
  43.     local SB = ModelPosition + (0.5 * (ModelSize*0.95))
  44.     return workspace:IsRegion3Empty(Region3.new(SA, SB))
  45. end
  46.  
  47.  
  48. local function Cloneit(Model)
  49.     local C = Cpy:Clone()
  50.     C.Parent = workspace
  51.     C:MakeJoints()
  52. end
  53.  
  54. local function DoTheDeed()
  55.     local isClear = isAreaEmpty()
  56.     if(isClear == true) then
  57.         if(deBug == true) then
  58.             print("Quick Spawn point is Clear \n Spawning clone...")
  59.         end
  60.         Cloneit(Cpy)
  61.     else
  62.         if(deBug == true) then
  63.             print("Spawn point is NOT clear waiting for spawn point to become clear...")
  64.         end
  65.         --// Sleep my script! :P
  66.     end
  67. end
  68.  
  69.  
  70. while true do
  71.     DoTheDeed()
  72.     wait(CloneMETime)
  73. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement