Guest User

KamikazeJAM108867's Placement script (BAD)

a guest
Nov 26th, 2018
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.70 KB | None | 0 0
  1. -- I told you not to read this:
  2.  
  3. local player = game.Players.LocalPlayer
  4. local mouse = player:GetMouse()
  5. local remote = game.ReplicatedStorage.ClientPlaced
  6. local items = game.ReplicatedStorage.Items
  7. local ismobile = game:GetService("UserInputService").TouchEnabled
  8. local placing = false
  9. local debounce = false
  10. local togglerotate = false
  11. local togglerotatepc = false
  12. local abovewater
  13. local boat
  14. local maxdistance = 100
  15. local canplace
  16. local menu = script.Parent.Parent:WaitForChild("main")
  17. local menu2 = script.Parent.Parent.Parent:WaitForChild("Inventory"):WaitForChild("main")
  18. local menu3 = script.Parent.Parent.Parent:WaitForChild("Teams"):WaitForChild("main")
  19.  
  20. function terrain(x, y, z)
  21.     local region = Region3.new(Vector3.new(x,y-1000,z), Vector3.new(x,y,z))
  22.     region = region:ExpandToGrid(4)
  23.     local material, occupancy = game.Workspace.Terrain:ReadVoxels(region, 4)
  24.     local size = material.Size
  25.     for x = 1, size.X do
  26.         for y = 1, size.Y do
  27.             for z = 1, size.Z do
  28.                 if material[x][y][z] == Enum.Material.Water then
  29.                     return true
  30.                 end
  31.             end
  32.         end
  33.     end
  34.     return false
  35. end
  36.  
  37. function place(name)
  38.     script.Parent:WaitForChild("Placing").Value = true
  39.     placing = true
  40.     menu.Position = UDim2.new(-0.225,0, 0.1,0)
  41.     menu2.Position = UDim2.new(1,0, 0.1,0)
  42.     menu3.Position = UDim2.new(-0.225,0, 0.1,0)
  43.     if game.ReplicatedStorage.Items:FindFirstChild(name) then
  44.         object = game.ReplicatedStorage.Items:FindFirstChild(name):Clone()
  45.         if ismobile == true then
  46.             script.Parent.Parent.Cancel.Visible = true
  47.             script.Parent.Parent.Rotate.Visible = true
  48.             script.Parent.Parent.Place.Visible = true
  49.         else
  50.             script.Parent.Parent.CancelPC.Visible = true
  51.         end
  52.         for i, v in pairs(object:GetChildren()) do
  53.             if v:IsA("BasePart") or v:IsA("UnionOperation") then
  54.                 v.BrickColor = BrickColor.new("Lime green")
  55.                 v.Transparency = 0.5
  56.                 for a, b in pairs(v:GetChildren()) do
  57.                     if b:IsA("BasePart") or b:IsA("UnionOperation") then
  58.                         b.BrickColor = BrickColor.new("Lime green")
  59.                         b.Transparency = 0.5
  60.                     end
  61.                 end
  62.             end
  63.         end
  64.         if object:FindFirstChild("Boat") and object:FindFirstChild("Boat").Value == true then
  65.             boat = true
  66.             local name = object.Name
  67.             object = game.ReplicatedStorage.Boats:FindFirstChild(name):Clone()
  68.         else
  69.             boat = false
  70.         end
  71.         object.Parent = game.Workspace
  72.         while placing == true do
  73.             local char = player.Character or player.CharacterAdded:Wait()
  74.             local torso = char:FindFirstChild("LowerTorso")
  75.             local mag = (torso.Position - object.PrimaryPart.Position).magnitude
  76.             if boat == true then
  77.                 if mag > maxdistance or abovewater == false then
  78.                     for i, v in pairs(object:GetChildren()) do
  79.                         if v:IsA("BasePart") then
  80.                             v.BrickColor = BrickColor.new("Really red")
  81.                             v.Transparency = 0.5
  82.                             for a, b in pairs(v:GetChildren()) do
  83.                                 if b:IsA("BasePart") or b:IsA("UnionOperation") then
  84.                                     b.BrickColor = BrickColor.new("Lime green")
  85.                                     b.Transparency = 0.5
  86.                                 end
  87.                             end
  88.                         end
  89.                     end
  90.                     canplace = false
  91.                 elseif mag <= maxdistance and abovewater == true then
  92.                     for i, v in pairs(object:GetChildren()) do
  93.                         if v:IsA("BasePart") then
  94.                             v.BrickColor = BrickColor.new("Lime green")
  95.                             v.Transparency = 0.5
  96.                             for a, b in pairs(v:GetChildren()) do
  97.                                 if b:IsA("BasePart") or b:IsA("UnionOperation") then
  98.                                     b.BrickColor = BrickColor.new("Lime green")
  99.                                     b.Transparency = 0.5
  100.                                 end
  101.                             end
  102.                         end
  103.                     end
  104.                     canplace = true
  105.                 end
  106.             elseif boat == false then
  107.                 if mag > maxdistance or abovewater == true then
  108.                     for i, v in pairs(object:GetChildren()) do
  109.                         if v:IsA("BasePart") then
  110.                             v.BrickColor = BrickColor.new("Really red")
  111.                             v.Transparency = 0.5
  112.                         end
  113.                     end
  114.                     canplace = false
  115.                 elseif mag <= maxdistance and abovewater == false then
  116.                     for i, v in pairs(object:GetChildren()) do
  117.                         if v:IsA("BasePart") then
  118.                             v.BrickColor = BrickColor.new("Lime green")
  119.                             v.Transparency = 0.5
  120.                         end
  121.                     end
  122.                     canplace = true
  123.                 end
  124.             end
  125.             if ismobile == false then
  126.                 local pos = object.PrimaryPart.Position
  127.                 local x = pos.X
  128.                 local y = pos.Y        
  129.                 local z = pos.Z
  130.                 abovewater = terrain(x,y,z)
  131.                 local posX = mouse.Hit.X
  132.                 local posY = 11
  133.                 local posZ = mouse.Hit.Z
  134.                 local size = object:GetModelSize()
  135.                 object:MoveTo(Vector3.new(posX, posY, posZ))
  136.                 mouse.Button1Down:Connect(function()
  137.                     if not debounce then
  138.                         debounce = true
  139.                         if placing == true then
  140.                             if ismobile == false then
  141.                                 if mag <= maxdistance then
  142.                                     if canplace == true then
  143.                                         if object.PrimaryPart then
  144.                                             local pos = object.PrimaryPart.CFrame
  145.                                             remote:FireServer(name, pos, object)
  146.                                             placing = false
  147.                                         end
  148.                                     end
  149.                                 else
  150.                                     --print("Toofar")
  151.                                 end
  152.                             end
  153.                         end
  154.                         wait(1)
  155.                         debounce = false
  156.                     end
  157.                 end)
  158.             elseif ismobile == true then
  159.                 repeat wait() until player.Character and player.Character:FindFirstChild("Humanoid")
  160.                 local torso = player.Character:WaitForChild("UpperTorso")
  161.                 local mpos = torso.Position + torso.CFrame.lookVector * 15
  162.                 local mposX = mpos.X
  163.                 local mposY = 11
  164.                 local mposZ = mpos.Z
  165.                 object:MoveTo(Vector3.new(mposX, mposY, mposZ))
  166.                 object.PrimaryPart.Orientation = orientation
  167.             end
  168.             script.Parent.Parent.Place.MouseButton1Down:Connect(function()
  169.                 if not debounce then
  170.                     debounce = true
  171.                     if placing == true then
  172.                         if ismobile == false then
  173.                             if mag <= maxdistance then
  174.                                 if canplace == true then
  175.                                     if object.PrimaryPart then
  176.                                         local pos = object.PrimaryPart.CFrame
  177.                                         remote:FireServer(name, pos, object)
  178.                                         placing = false
  179.                                     end
  180.                                 end
  181.                             else
  182.                                 --print("Toofar")
  183.                             end
  184.                         end
  185.                     end
  186.                     wait(1)
  187.                     debounce = false
  188.                     script.Parent:WaitForChild("Placing").Value = false
  189.                     script.Parent:WaitForChild("PlaceName").Value = nil
  190.                 end
  191.             end)
  192.         wait()
  193.         end
  194.     else
  195.        
  196.     end
  197.     cancel()
  198. end
  199.  
  200. function cancel()
  201.     if object then
  202.         object:Destroy()
  203.     end
  204.     placing = false
  205.     script.Parent:WaitForChild("Placing").Value = false
  206.     script.Parent:WaitForChild("PlaceName").Value = ""
  207.     script.Parent.Parent.Cancel.Visible = false
  208.     script.Parent.Parent.CancelPC.Visible = false
  209.     script.Parent.Parent.Rotate.Visible = false
  210.     script.Parent.Parent.Place.Visible = false
  211. end
  212.  
  213. mouse.KeyDown:connect(function(key)
  214.     if key == "x" then
  215.         cancel()
  216.     end
  217. end)
  218.  
  219. mouse.KeyDown:connect(function(key)
  220.     if key == "r" then
  221.         if placing == true then
  222.             togglerotatepc = true
  223.             repeat
  224.             object:SetPrimaryPartCFrame(object:GetPrimaryPartCFrame() * CFrame.Angles(0, math.rad(5), 0))
  225.             wait()
  226.             until togglerotatepc == false
  227.         end
  228.     end
  229. end)
  230.  
  231. mouse.KeyUp:Connect(function(key)
  232.     if key == "r" then
  233.         togglerotatepc = false
  234.     end
  235. end)
  236.  
  237. script.Parent.Parent.Cancel.MouseButton1Down:Connect(function()
  238.     cancel()
  239. end)
  240.  
  241. script.Parent.Parent.Rotate.MouseButton1Down:Connect(function()
  242.     if placing == true then
  243.         togglerotate = true
  244.         repeat
  245.         object:SetPrimaryPartCFrame(object:GetPrimaryPartCFrame() * CFrame.Angles(0, math.rad(5), 0))       wait()
  246.         until togglerotate == false
  247.     end
  248. end)
  249.  
  250. script.Parent.Parent.Rotate.MouseButton1Up:Connect(function()
  251.     togglerotate = false
  252. end)
  253.  
  254. mouse.KeyDown:connect(function(key)
  255.     if key == "c" or key == "t" then
  256.         cancel()
  257.     end
  258. end)
  259.  
  260. while wait() do
  261.     if placing == false then
  262.         if script.Parent.Placing.Value == true and script.Parent.PlaceName.Value ~= nil then
  263.             local name = tostring(script.Parent.PlaceName.Value)
  264.             place(name)
  265.         end
  266.     else
  267.         print("placing")
  268.     end
  269. end
Advertisement
Add Comment
Please, Sign In to add comment