Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.04 KB | None | 0 0
  1. local tool = script.Parent
  2. local player = game.Players.LocalPlayer
  3. local mouse = player:GetMouse()
  4. local Current = script.Parent:WaitForChild("Current")
  5. local eq = false
  6. local snap = false
  7. local CurrentCFrame
  8. local objCurrent
  9. local Base = game.Workspace.TestBase
  10. local lastSocket
  11. local classes =
  12. {
  13. ["WallTest"] = "Wall",
  14. ["CeilingTest"] = "Ceiling",
  15. ["Foundation"] = "Foundation",
  16. ["DoorFrame"] = "Wall",
  17. ["Stairs"] = "FoundationPlace",
  18. ["TC"] = "TablePlacement",
  19. }
  20.  
  21. local FoundationWhitelist = {Base.Foundation.FoundationSockets}
  22. local WallWhitelist = {Base.Foundation.WallParts}
  23.  
  24. mouse.Button1Down:connect(function()
  25. if eq then
  26. local Placed = game.ReplicatedStorage.PlaceObject:InvokeServer(Current.Value, CurrentCFrame)
  27. local Sockets = Placed:FindFirstChild("FoundationSockets")
  28. local WallParts = Placed:FindFirstChild("WallParts")
  29.  
  30. if Sockets then
  31. local c = Sockets:GetChildren()
  32. for i = 1, #c do
  33. FoundationWhitelist[#FoundationWhitelist + 1] = c[i]
  34. end
  35. end
  36.  
  37. if WallParts and WallParts.Parent.Name ~= "WallTest" then
  38. local c = WallParts:GetChildren()
  39. for i = 1, #c do print(c[i])
  40. FoundationWhitelist[#FoundationWhitelist + 1] = c[i]
  41. end
  42. end
  43. end
  44.  
  45. end)
  46.  
  47. function GetClass(item)
  48. return classes[item]
  49. end
  50.  
  51. tool.Equipped:Connect(function()
  52. eq = true
  53. end)
  54.  
  55. tool.Unequipped:Connect(function()
  56. eq = false
  57. end)
  58. function TransparentModel(model)
  59. for i,v in pairs(model:GetChildren()) do
  60. if v:IsA("Part") and v.Transparency ~= 1 then
  61. v.Transparency = .5
  62. v.CanCollide = false
  63. else
  64. TransparentModel(v)
  65. end
  66. end
  67.  
  68. end
  69. function renderModel(CFrameVal)
  70. if objCurrent and objCurrent.PrimaryPart then
  71. objCurrent:SetPrimaryPartCFrame(CurrentCFrame)
  72. else
  73. game.Workspace.CurrentCamera:ClearAllChildren()
  74. local model = Current.Value:Clone()
  75. model.Parent = game.Workspace.CurrentCamera
  76. model:SetPrimaryPartCFrame(CFrameVal)
  77. objCurrent = model
  78. TransparentModel(model)
  79. end
  80. end
  81.  
  82. function FoundationFreePlace()
  83. local ray = Ray.new(game.Workspace.Camera.CFrame.p, (mouse.Hit.p - game.Workspace.Camera.CFrame.p).unit * 300)
  84. local part, position = workspace:FindPartOnRayWithWhitelist(ray, FoundationWhitelist)
  85.  
  86. if part and part.Parent.Name == "FoundationSockets" then
  87. snap = true
  88. else snap = false
  89. end
  90. CurrentCFrame = CFrame.new(position)
  91. renderModel(CurrentCFrame)
  92.  
  93. end
  94. function Foundation()
  95. local ray = Ray.new(game.Workspace.Camera.CFrame.p, (mouse.Hit.p - game.Workspace.Camera.CFrame.p).unit * 300)
  96. local part, position = workspace:FindPartOnRayWithWhitelist(ray, FoundationWhitelist)
  97. if part and part.Parent.Parent.Name == "Foundation" then
  98.  
  99. snap = true
  100. if CurrentCFrame == lastSocket then
  101. print(CurrentCFrame, "Val", lastSocket)
  102. end
  103. CurrentCFrame = lastSocket
  104. if part.Parent.Name == "FoundationSockets" then
  105. lastSocket = part.CFrame
  106. --print(part, part.Parent, lastSocket)
  107. CurrentCFrame = CFrame.new(part.Position)
  108. renderModel(CurrentCFrame)
  109. else
  110. renderModel(lastSocket)
  111.  
  112. end
  113. else
  114. snap = false
  115. end
  116.  
  117. end
  118. function WallHighlight()
  119. local ray = Ray.new(game.Workspace.Camera.CFrame.p, (mouse.Hit.p - game.Workspace.Camera.CFrame.p).unit * 300)
  120. local part, position = workspace:FindPartOnRayWithWhitelist(ray, WallWhitelist)
  121.  
  122. if part and part.Parent.Name == "WallParts" and part.Parent.Parent.Parent == Base then
  123. local newSocket = part.Parent.Parent.PlacementParts:FindFirstChild(part.Name)
  124. --print(newSocket)
  125. CurrentCFrame = newSocket.CFrame
  126. renderModel(CurrentCFrame)
  127. end
  128. end
  129. game:GetService("RunService").RenderStepped:Connect(function()
  130. if Current.Value then
  131. if eq and snap then
  132. if GetClass(Current.Value.Name) == "Foundation" then
  133. Foundation()
  134. elseif GetClass(Current.Value.Name) == "Wall" then
  135. WallHighlight()
  136. end
  137. elseif eq and not snap then
  138. if GetClass(Current.Value.Name) == "Foundation" then
  139. FoundationFreePlace()
  140. elseif GetClass(Current.Value.Name) == "Wall" then
  141. WallHighlight()
  142. end
  143. end
  144. end
  145. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement