Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tool = script.Parent
- local player = game.Players.LocalPlayer
- local mouse = player:GetMouse()
- local Current = script.Parent:WaitForChild("Current")
- local eq = false
- local snap = false
- local CurrentCFrame
- local objCurrent
- local Base = game.Workspace.TestBase
- local lastSocket
- local classes =
- {
- ["WallTest"] = "Wall",
- ["CeilingTest"] = "Ceiling",
- ["Foundation"] = "Foundation",
- ["DoorFrame"] = "Wall",
- ["Stairs"] = "FoundationPlace",
- ["TC"] = "TablePlacement",
- }
- local FoundationWhitelist = {Base.Foundation.FoundationSockets}
- local WallWhitelist = {Base.Foundation.WallParts}
- mouse.Button1Down:connect(function()
- if eq then
- local Placed = game.ReplicatedStorage.PlaceObject:InvokeServer(Current.Value, CurrentCFrame)
- local Sockets = Placed:FindFirstChild("FoundationSockets")
- local WallParts = Placed:FindFirstChild("WallParts")
- if Sockets then
- local c = Sockets:GetChildren()
- for i = 1, #c do
- FoundationWhitelist[#FoundationWhitelist + 1] = c[i]
- end
- end
- if WallParts and WallParts.Parent.Name ~= "WallTest" then
- local c = WallParts:GetChildren()
- for i = 1, #c do print(c[i])
- FoundationWhitelist[#FoundationWhitelist + 1] = c[i]
- end
- end
- end
- end)
- function GetClass(item)
- return classes[item]
- end
- tool.Equipped:Connect(function()
- eq = true
- end)
- tool.Unequipped:Connect(function()
- eq = false
- end)
- function TransparentModel(model)
- for i,v in pairs(model:GetChildren()) do
- if v:IsA("Part") and v.Transparency ~= 1 then
- v.Transparency = .5
- v.CanCollide = false
- else
- TransparentModel(v)
- end
- end
- end
- function renderModel(CFrameVal)
- if objCurrent and objCurrent.PrimaryPart then
- objCurrent:SetPrimaryPartCFrame(CurrentCFrame)
- else
- game.Workspace.CurrentCamera:ClearAllChildren()
- local model = Current.Value:Clone()
- model.Parent = game.Workspace.CurrentCamera
- model:SetPrimaryPartCFrame(CFrameVal)
- objCurrent = model
- TransparentModel(model)
- end
- end
- function FoundationFreePlace()
- local ray = Ray.new(game.Workspace.Camera.CFrame.p, (mouse.Hit.p - game.Workspace.Camera.CFrame.p).unit * 300)
- local part, position = workspace:FindPartOnRayWithWhitelist(ray, FoundationWhitelist)
- if part and part.Parent.Name == "FoundationSockets" then
- snap = true
- else snap = false
- end
- CurrentCFrame = CFrame.new(position)
- renderModel(CurrentCFrame)
- end
- function Foundation()
- local ray = Ray.new(game.Workspace.Camera.CFrame.p, (mouse.Hit.p - game.Workspace.Camera.CFrame.p).unit * 300)
- local part, position = workspace:FindPartOnRayWithWhitelist(ray, FoundationWhitelist)
- if part and part.Parent.Parent.Name == "Foundation" then
- snap = true
- if CurrentCFrame == lastSocket then
- print(CurrentCFrame, "Val", lastSocket)
- end
- CurrentCFrame = lastSocket
- if part.Parent.Name == "FoundationSockets" then
- lastSocket = part.CFrame
- --print(part, part.Parent, lastSocket)
- CurrentCFrame = CFrame.new(part.Position)
- renderModel(CurrentCFrame)
- else
- renderModel(lastSocket)
- end
- else
- snap = false
- end
- end
- function WallHighlight()
- local ray = Ray.new(game.Workspace.Camera.CFrame.p, (mouse.Hit.p - game.Workspace.Camera.CFrame.p).unit * 300)
- local part, position = workspace:FindPartOnRayWithWhitelist(ray, WallWhitelist)
- if part and part.Parent.Name == "WallParts" and part.Parent.Parent.Parent == Base then
- local newSocket = part.Parent.Parent.PlacementParts:FindFirstChild(part.Name)
- --print(newSocket)
- CurrentCFrame = newSocket.CFrame
- renderModel(CurrentCFrame)
- end
- end
- game:GetService("RunService").RenderStepped:Connect(function()
- if Current.Value then
- if eq and snap then
- if GetClass(Current.Value.Name) == "Foundation" then
- Foundation()
- elseif GetClass(Current.Value.Name) == "Wall" then
- WallHighlight()
- end
- elseif eq and not snap then
- if GetClass(Current.Value.Name) == "Foundation" then
- FoundationFreePlace()
- elseif GetClass(Current.Value.Name) == "Wall" then
- WallHighlight()
- end
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement