Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- I told you not to read this:
- local player = game.Players.LocalPlayer
- local mouse = player:GetMouse()
- local remote = game.ReplicatedStorage.ClientPlaced
- local items = game.ReplicatedStorage.Items
- local ismobile = game:GetService("UserInputService").TouchEnabled
- local placing = false
- local debounce = false
- local togglerotate = false
- local togglerotatepc = false
- local abovewater
- local boat
- local maxdistance = 100
- local canplace
- local menu = script.Parent.Parent:WaitForChild("main")
- local menu2 = script.Parent.Parent.Parent:WaitForChild("Inventory"):WaitForChild("main")
- local menu3 = script.Parent.Parent.Parent:WaitForChild("Teams"):WaitForChild("main")
- function terrain(x, y, z)
- local region = Region3.new(Vector3.new(x,y-1000,z), Vector3.new(x,y,z))
- region = region:ExpandToGrid(4)
- local material, occupancy = game.Workspace.Terrain:ReadVoxels(region, 4)
- local size = material.Size
- for x = 1, size.X do
- for y = 1, size.Y do
- for z = 1, size.Z do
- if material[x][y][z] == Enum.Material.Water then
- return true
- end
- end
- end
- end
- return false
- end
- function place(name)
- script.Parent:WaitForChild("Placing").Value = true
- placing = true
- menu.Position = UDim2.new(-0.225,0, 0.1,0)
- menu2.Position = UDim2.new(1,0, 0.1,0)
- menu3.Position = UDim2.new(-0.225,0, 0.1,0)
- if game.ReplicatedStorage.Items:FindFirstChild(name) then
- object = game.ReplicatedStorage.Items:FindFirstChild(name):Clone()
- if ismobile == true then
- script.Parent.Parent.Cancel.Visible = true
- script.Parent.Parent.Rotate.Visible = true
- script.Parent.Parent.Place.Visible = true
- else
- script.Parent.Parent.CancelPC.Visible = true
- end
- for i, v in pairs(object:GetChildren()) do
- if v:IsA("BasePart") or v:IsA("UnionOperation") then
- v.BrickColor = BrickColor.new("Lime green")
- v.Transparency = 0.5
- for a, b in pairs(v:GetChildren()) do
- if b:IsA("BasePart") or b:IsA("UnionOperation") then
- b.BrickColor = BrickColor.new("Lime green")
- b.Transparency = 0.5
- end
- end
- end
- end
- if object:FindFirstChild("Boat") and object:FindFirstChild("Boat").Value == true then
- boat = true
- local name = object.Name
- object = game.ReplicatedStorage.Boats:FindFirstChild(name):Clone()
- else
- boat = false
- end
- object.Parent = game.Workspace
- while placing == true do
- local char = player.Character or player.CharacterAdded:Wait()
- local torso = char:FindFirstChild("LowerTorso")
- local mag = (torso.Position - object.PrimaryPart.Position).magnitude
- if boat == true then
- if mag > maxdistance or abovewater == false then
- for i, v in pairs(object:GetChildren()) do
- if v:IsA("BasePart") then
- v.BrickColor = BrickColor.new("Really red")
- v.Transparency = 0.5
- for a, b in pairs(v:GetChildren()) do
- if b:IsA("BasePart") or b:IsA("UnionOperation") then
- b.BrickColor = BrickColor.new("Lime green")
- b.Transparency = 0.5
- end
- end
- end
- end
- canplace = false
- elseif mag <= maxdistance and abovewater == true then
- for i, v in pairs(object:GetChildren()) do
- if v:IsA("BasePart") then
- v.BrickColor = BrickColor.new("Lime green")
- v.Transparency = 0.5
- for a, b in pairs(v:GetChildren()) do
- if b:IsA("BasePart") or b:IsA("UnionOperation") then
- b.BrickColor = BrickColor.new("Lime green")
- b.Transparency = 0.5
- end
- end
- end
- end
- canplace = true
- end
- elseif boat == false then
- if mag > maxdistance or abovewater == true then
- for i, v in pairs(object:GetChildren()) do
- if v:IsA("BasePart") then
- v.BrickColor = BrickColor.new("Really red")
- v.Transparency = 0.5
- end
- end
- canplace = false
- elseif mag <= maxdistance and abovewater == false then
- for i, v in pairs(object:GetChildren()) do
- if v:IsA("BasePart") then
- v.BrickColor = BrickColor.new("Lime green")
- v.Transparency = 0.5
- end
- end
- canplace = true
- end
- end
- if ismobile == false then
- local pos = object.PrimaryPart.Position
- local x = pos.X
- local y = pos.Y
- local z = pos.Z
- abovewater = terrain(x,y,z)
- local posX = mouse.Hit.X
- local posY = 11
- local posZ = mouse.Hit.Z
- local size = object:GetModelSize()
- object:MoveTo(Vector3.new(posX, posY, posZ))
- mouse.Button1Down:Connect(function()
- if not debounce then
- debounce = true
- if placing == true then
- if ismobile == false then
- if mag <= maxdistance then
- if canplace == true then
- if object.PrimaryPart then
- local pos = object.PrimaryPart.CFrame
- remote:FireServer(name, pos, object)
- placing = false
- end
- end
- else
- --print("Toofar")
- end
- end
- end
- wait(1)
- debounce = false
- end
- end)
- elseif ismobile == true then
- repeat wait() until player.Character and player.Character:FindFirstChild("Humanoid")
- local torso = player.Character:WaitForChild("UpperTorso")
- local mpos = torso.Position + torso.CFrame.lookVector * 15
- local mposX = mpos.X
- local mposY = 11
- local mposZ = mpos.Z
- object:MoveTo(Vector3.new(mposX, mposY, mposZ))
- object.PrimaryPart.Orientation = orientation
- end
- script.Parent.Parent.Place.MouseButton1Down:Connect(function()
- if not debounce then
- debounce = true
- if placing == true then
- if ismobile == false then
- if mag <= maxdistance then
- if canplace == true then
- if object.PrimaryPart then
- local pos = object.PrimaryPart.CFrame
- remote:FireServer(name, pos, object)
- placing = false
- end
- end
- else
- --print("Toofar")
- end
- end
- end
- wait(1)
- debounce = false
- script.Parent:WaitForChild("Placing").Value = false
- script.Parent:WaitForChild("PlaceName").Value = nil
- end
- end)
- wait()
- end
- else
- end
- cancel()
- end
- function cancel()
- if object then
- object:Destroy()
- end
- placing = false
- script.Parent:WaitForChild("Placing").Value = false
- script.Parent:WaitForChild("PlaceName").Value = ""
- script.Parent.Parent.Cancel.Visible = false
- script.Parent.Parent.CancelPC.Visible = false
- script.Parent.Parent.Rotate.Visible = false
- script.Parent.Parent.Place.Visible = false
- end
- mouse.KeyDown:connect(function(key)
- if key == "x" then
- cancel()
- end
- end)
- mouse.KeyDown:connect(function(key)
- if key == "r" then
- if placing == true then
- togglerotatepc = true
- repeat
- object:SetPrimaryPartCFrame(object:GetPrimaryPartCFrame() * CFrame.Angles(0, math.rad(5), 0))
- wait()
- until togglerotatepc == false
- end
- end
- end)
- mouse.KeyUp:Connect(function(key)
- if key == "r" then
- togglerotatepc = false
- end
- end)
- script.Parent.Parent.Cancel.MouseButton1Down:Connect(function()
- cancel()
- end)
- script.Parent.Parent.Rotate.MouseButton1Down:Connect(function()
- if placing == true then
- togglerotate = true
- repeat
- object:SetPrimaryPartCFrame(object:GetPrimaryPartCFrame() * CFrame.Angles(0, math.rad(5), 0)) wait()
- until togglerotate == false
- end
- end)
- script.Parent.Parent.Rotate.MouseButton1Up:Connect(function()
- togglerotate = false
- end)
- mouse.KeyDown:connect(function(key)
- if key == "c" or key == "t" then
- cancel()
- end
- end)
- while wait() do
- if placing == false then
- if script.Parent.Placing.Value == true and script.Parent.PlaceName.Value ~= nil then
- local name = tostring(script.Parent.PlaceName.Value)
- place(name)
- end
- else
- print("placing")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment