Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local RunService = game:GetService("RunService")
- local UIS = game:GetService("UserInputService")
- local player = game.Players.LocalPlayer
- local mouse = player:GetMouse()
- local posX
- local PosY
- local PosZ
- local Rot
- local button = script.Parent.TextButton
- local Button2 = script.Parent.floor
- local model = game.ReplicatedStorage.wall:Clone()
- model.Parent = workspace
- local GridSize = 6.0
- local CanStart = true
- local IsPlacing = nil
- local CanPlace = nil
- local function snap()
- posX = math.floor(mouse.Hit.X / GridSize + 0.5) * GridSize
- PosY = model.PrimaryPart.Position.Y
- PosZ = math.floor(mouse.Hit.Z / GridSize + 0.5) * GridSize
- end
- local function Placement()
- if IsPlacing and CanPlace then
- local PlacedModel = model:Clone()
- PlacedModel.Parent = workspace.PlacedObjects
- local NOcanCollide = PlacedModel:GetChildren()
- for i, v in pairs(NOcanCollide) do
- v.CanCollide = true
- end
- IsPlacing = false
- CanPlace = false
- CanStart = true
- model:Destroy()
- end
- end
- local function movement()
- if IsPlacing and CanPlace and not CanStart then
- mouse.TargetFilter = model
- snap()
- model:SetPrimaryPartCFrame(CFrame.new(posX, PosY, PosZ))
- else
- return mouse.Hit.p
- end
- local function StartPlacementWall()
- if CanStart then
- model = game:GetService("ReplicatedStorage").wall:clone()
- model.Parent = workspace
- IsPlacing = true
- CanPlace = true
- CanStart = false
- mouse.Move:Connect(movement)
- end
- end
- local function StartPlacementfloor()
- if CanStart then
- model = game:GetService("ReplicatedStorage").floor:clone()
- model.Parent = workspace
- IsPlacing = true
- CanPlace = true
- CanStart = false
- mouse.Move:Connect(movement)
- end
- end
- local function Rotation(input, GPE)
- if IsPlacing and CanPlace and not CanStart and input.KeyCode == Enum.KeyCode.R then
- Rot = Rot + 90
- Model:SetPrimaryPartCFrame(Model.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(Rot), 0))
- end
- end
- mouse.Button1Down:Connect(Placement)
- button.MouseButton1Click:Connect(StartPlacementWall)
- Button2.MouseButton1Click:Connect(StartPlacementfloor)
- UIS.InputBegan:Connect(Rotation)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement