Mryeetmemes

UnitManager

Dec 9th, 2021
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.16 KB | None | 0 0
  1. local RunService = game:GetService("RunService")
  2. local Player = game.Players.LocalPlayer
  3. local Mouse = Player:GetMouse()
  4. local Unit = nil
  5.  
  6. local RotationX = 0
  7. local RotationY = 0
  8. local RotationZ = 0
  9.  
  10. Mouse.Button1Down:Connect(function()
  11.     if Unit then
  12.         Unit:Destroy()
  13.     end
  14. end)
  15.  
  16. local function GetTouchingParts(part)
  17.    local connection = part.Touched:Connect(function() end)
  18.    local results = part:GetTouchingParts()
  19.    connection:Disconnect()
  20.    return results
  21. end
  22.  
  23. function doesCollide(unit, obj)
  24.     if unit and obj then
  25.         local results = GetTouchingParts(obj)
  26.         for _, v in pairs(results) do
  27.             if unit:FindFirstChild(v) == false then
  28.                 if v == "NoPlacePart" then
  29.                     return true
  30.                 end
  31.             end
  32.         end
  33.         return false
  34.     else
  35.         return false
  36.     end
  37. end
  38.  
  39. local module = {}
  40.     function module.placeUnitHint()
  41.         script.Parent.Configuration.UnitOrientation.Value = Vector3.new(0, 0, 0)
  42.         if Unit then
  43.             Unit:Destroy()
  44.         end
  45.         Unit = script.Parent.Configuration.UnitChoosed.Value
  46.         Unit = Unit:Clone()
  47.         if Unit:IsA("Model") then
  48.             if Unit:FindFirstChild("Humanoid") then
  49.                    
  50.             else
  51.                 for i, v in pairs(Unit:GetChildren()) do
  52.                     if v:IsA("Part") or v:IsA("MeshPart") then
  53.                         v.Transparency = 0.5
  54.                     end
  55.                 end
  56.             end
  57.         else
  58.             Unit.Transparency = 0.5
  59.         end
  60.         if Unit:IsA("Model") then
  61.             for i, v in pairs(Unit:GetChildren()) do
  62.                 if v:IsA("Part") or v:IsA("MeshPart") then
  63.                     v.CanCollide = false
  64.                 end
  65.             end
  66.         else
  67.             Unit.CanCollide = false
  68.         end
  69.         if Unit:FindFirstChild("ClickDetector") then
  70.             Unit.ClickDetector.MaxActivationDistance = 0
  71.         end
  72.         Unit.Parent = game.Workspace
  73.         Mouse.TargetFilter = Unit
  74.         script.Parent.Configuration.UnitEditor.Value = true
  75.         RunService.RenderStepped:Connect(function()
  76.             if Unit:IsA("Model") then
  77.                 if Unit.PrimaryPart then
  78.                     Unit:SetPrimaryPartCFrame(CFrame.new(Mouse.Hit.p))
  79.                     Unit:SetPrimaryPartCFrame(CFrame.new(Unit.PrimaryPart.Position.X + Unit.PrimaryPart.Size.X / 2, Unit.PrimaryPart.Position.Y + Unit.PrimaryPart.Size.Y / 2, Unit.PrimaryPart.Position.Z + Unit.PrimaryPart.Size.Z / 2))
  80.                 end
  81.             else
  82.                 Unit.Position = Mouse.Hit.p
  83.                 Unit.Position = Vector3.new(Unit.Position.X + Unit.Size.X / 2, Unit.Position.Y + Unit.Size.Y / 2, Unit.Position.Z + Unit.Size.Z / 2)
  84.             end
  85.             if game.Workspace:FindFirstChild(Player.Name) then
  86.                 if game.Workspace[Player.Name]:FindFirstChild("Humanoid") then
  87.                     if game.Workspace[Player.Name]:FindFirstChild("HumanoidRootPart") then
  88.                         if Unit:IsA("Model") then
  89.                             if Unit.PrimaryPart then
  90.                                 if (game.Workspace[Player.Name].HumanoidRootPart.Position - Unit.PrimaryPart.Position).magnitude < script.Parent.Configuration.UnitPlaceDistance.Value then
  91.                                     script.Parent.Configuration.UnitPlaceable.Value = true
  92.                                 else
  93.                                     script.Parent.Configuration.UnitPlaceable.Value = false
  94.                                 end
  95.                                 if doesCollide(Unit, Unit:WaitForChild("Right Leg")) then
  96.                                     script.Parent.Configuration.UnitPlaceable.Value = false
  97.                                 else
  98.                                     script.Parent.Configuration.UnitPlaceable.Value = true
  99.                                 end
  100.                             end
  101.                         else
  102.                             if (game.Workspace[Player.Name].HumanoidRootPart.Position - Unit.Position).magnitude < script.Parent.Configuration.UnitPlaceDistance.Value then
  103.                                 Unit.BrickColor = BrickColor.Green()
  104.                                 script.Parent.Configuration.UnitPlaceable.Value = true
  105.                             else
  106.                                 Unit.BrickColor = BrickColor.Red()
  107.                                 script.Parent.Configuration.UnitPlaceable.Value = false
  108.                             end
  109.                         end
  110.                     end
  111.                 end
  112.             end
  113.         end)
  114.         game:GetService("UserInputService").InputBegan:Connect(function(inputObject, gameProcessedEvent)
  115.             if script.Parent.Configuration.UnitEditor.Value == true then
  116.                 if inputObject.KeyCode == Enum.KeyCode.Q then
  117.                     RotationX = RotationX + 90
  118.                 end
  119.                 if inputObject.KeyCode == Enum.KeyCode.E then
  120.                     RotationZ = RotationZ + 90
  121.                 end
  122.                 script.Parent.Configuration.UnitOrientation.Value = Vector3.new(RotationX, RotationY, RotationZ)
  123.                 if Unit:IsA("Model") then
  124.                     -- Cannot rotate group
  125.                 else
  126.                     Unit.Orientation = script.Parent.Configuration.UnitOrientation.Value
  127.                 end
  128.             end
  129.         end)
  130.     end
  131. return module
Advertisement
Add Comment
Please, Sign In to add comment