Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. local RunService = game:GetService("RunService")
  2. local UIS = game:GetService("UserInputService")
  3. local player = game.Players.LocalPlayer
  4. local mouse = player:GetMouse()
  5. local posX
  6. local PosY
  7. local PosZ
  8. local Rot
  9.  
  10.  
  11. local button = script.Parent.TextButton
  12. local Button2 = script.Parent.floor
  13. local model = game.ReplicatedStorage.wall:Clone()
  14. model.Parent = workspace
  15. local GridSize = 6.0
  16. local CanStart = true
  17. local IsPlacing = nil
  18. local CanPlace = nil
  19.  
  20. local function snap()
  21. posX = math.floor(mouse.Hit.X / GridSize + 0.5) * GridSize
  22. PosY = model.PrimaryPart.Position.Y
  23. PosZ = math.floor(mouse.Hit.Z / GridSize + 0.5) * GridSize
  24. end
  25.  
  26. local function Placement()
  27. if IsPlacing and CanPlace then
  28. local PlacedModel = model:Clone()
  29. PlacedModel.Parent = workspace.PlacedObjects
  30. local NOcanCollide = PlacedModel:GetChildren()
  31.  
  32. for i, v in pairs(NOcanCollide) do
  33. v.CanCollide = true
  34. end
  35.  
  36.  
  37.  
  38. IsPlacing = false
  39. CanPlace = false
  40. CanStart = true
  41.  
  42. model:Destroy()
  43. end
  44. end
  45. local function movement()
  46. if IsPlacing and CanPlace and not CanStart then
  47. mouse.TargetFilter = model
  48.  
  49. snap()
  50.  
  51. model:SetPrimaryPartCFrame(CFrame.new(posX, PosY, PosZ))
  52. else
  53. return mouse.Hit.p
  54. end
  55.  
  56. local function StartPlacementWall()
  57. if CanStart then
  58. model = game:GetService("ReplicatedStorage").wall:clone()
  59. model.Parent = workspace
  60. IsPlacing = true
  61. CanPlace = true
  62. CanStart = false
  63.  
  64. mouse.Move:Connect(movement)
  65. end
  66. end
  67.  
  68. local function StartPlacementfloor()
  69. if CanStart then
  70. model = game:GetService("ReplicatedStorage").floor:clone()
  71. model.Parent = workspace
  72. IsPlacing = true
  73. CanPlace = true
  74. CanStart = false
  75.  
  76. mouse.Move:Connect(movement)
  77. end
  78. end
  79.  
  80. local function Rotation(input, GPE)
  81. if IsPlacing and CanPlace and not CanStart and input.KeyCode == Enum.KeyCode.R then
  82. Rot = Rot + 90
  83.  
  84. Model:SetPrimaryPartCFrame(Model.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(Rot), 0))
  85. end
  86. end
  87.  
  88.  
  89.  
  90.  
  91. mouse.Button1Down:Connect(Placement)
  92. button.MouseButton1Click:Connect(StartPlacementWall)
  93. Button2.MouseButton1Click:Connect(StartPlacementfloor)
  94.  
  95. UIS.InputBegan:Connect(Rotation)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement