i made the build script now, i'm just working on the collision part so what i done is when the part is not on top of the plot i just set an anchor Position so its anchor to that position until the mouse.hit .position is equal to the top of the plot and i added offset so all parts of the model is above the part
this script works for models it also makes a semi transparent blueprint, it also has destroy mode so it would destroy the model it works by pressing right click and pressing left click on the model and right click again to go back to build mode, and just click to build, it has changeable grid too. This script is not done yet, i'm making it so scroll wheel goes through the build selection and more stuff
001 | local Player = game.Players.LocalPlayer |
002 | local char = Player.Character or Player.CharacterAdded:Wait() |
003 | local RunService = game:GetService( "RunService" ) |
004 | local UserInputService = game:GetService( "UserInputService" ) |
005 | local Mouse = Player:GetMouse() |
007 | local Model = game.Workspace.Conveyor |
008 | local ModelPrimaryPart = Model.PrimaryPart |
010 | local Plot = game.Workspace.Plots.Plot |
011 | local HalfSizeforX = Plot.Size.X/ 2 |
012 | local HalfSizeforZ = Plot.Size.Z/ 2 |
013 | local Heightlimit = 100 |
019 | local AngleY = math.rad( 0 ) |
020 | local RotationState = 1 |
022 | local ModelCloneBluePrint = Model:Clone() |
023 | ModelCloneBluePrint.Parent = game.Workspace |
024 | ModelCloneBluePrint.Name = ModelCloneBluePrint.Name.. "BluePrint" |
025 | local ModelCloneBluePrintChildren = ModelCloneBluePrint:GetDescendants() |
026 | for index,value in pairs (ModelCloneBluePrintChildren) do |
027 | if not value:IsA( "Model" ) |
029 | value.Transparency = 0.5 |
030 | value.CanCollide = false |
031 | if value.Name = = "PrimaryPart" or value.Name = = "TouchDeny" |
032 | then value.Transparency = 1 |
037 | UserInputService.InputBegan:Connect( function (key) |
038 | if key.KeyCode = = Enum.KeyCode.R then |
039 | RotationState = RotationState + 1 |
040 | AngleY = AngleY + math.rad( 45 ) |
041 | if AngleY = = math.rad( 360 ) then |
048 | local DestroyMode = false |
049 | RunService.RenderStepped:Connect( function () |
050 | if DestroyMode = = false |
052 | Mouse.TargetFilter = ModelCloneBluePrint |
054 | PosX = math.floor(Mouse.Hit.X / Gridsize + 0.5 ) * Gridsize |
055 | PosY = math.floor(Mouse.Hit.Y / Gridsize + 0.5 ) * Gridsize |
056 | PosZ = math.floor(Mouse.Hit.Z / Gridsize + 0.5 ) * Gridsize |
058 | local ModelXOffset = ModelPrimaryPart.Size.X/ 2 |
059 | local ModelYOffset = ModelPrimaryPart.Size.Y/ 2 |
060 | local ModelZOffset = ModelPrimaryPart.Size.Z/ 2 |
062 | if RotationState = = 1 or RotationState = = 3 then |
063 | HalfSizeforX = Plot.Size.X/ 2 - ModelXOffset |
064 | HalfSizeforZ = Plot.Size.Z/ 2 - ModelZOffset |
065 | elseif RotationState = = 2 or RotationState = = 4 then |
066 | HalfSizeforX = Plot.Size.X/ 2 - ModelZOffset |
067 | HalfSizeforZ = Plot.Size.Z/ 2 - ModelXOffset |
070 | local BorderPosX = Plot.Position.X + HalfSizeforX |
071 | local BorderNegX = Plot.Position.X - HalfSizeforX |
072 | local BorderCelY = Plot.Position.Y + Heightlimit |
073 | local BorderFlrY = Plot.Position.Y |
074 | local BorderPosZ = Plot.Position.Z + HalfSizeforZ |
075 | local BorderNegZ = Plot.Position.Z - HalfSizeforZ |
077 | if PosX > BorderPosX then |
080 | elseif PosX < BorderNegX then |
085 | if PosZ > BorderPosZ then |
088 | elseif PosZ < BorderNegZ then |
092 | local ModelPrimaryPart = ModelCloneBluePrint.PrimaryPart |
093 | local ModelPoint 1 = ModelPrimaryPart.Size/ 2 + ModelPrimaryPart.Position |
094 | local ModelPoint 2 = ModelPrimaryPart.Size/ 2 - ModelPrimaryPart.Position |
095 | local ModelRegion = Region 3. new(ModelPoint 1 ,ModelPoint 2 ) |
096 | local Obstacle = workspace:FindPartsInRegion 3 WithIgnoreList(ModelRegion,char, math.huge ) |
097 | for i,v in pairs (Obstacle) do |
098 | local Obstacles = v.Parent |
099 | local ObstaclePrimaryPart = v.PrimaryPart |
103 | PosY = PosY + ModelYOffset |
104 | ModelCloneBluePrint:SetPrimaryPartCFrame(CFrame.new(PosX,PosY,PosZ) * CFrame.Angles( 0 ,AngleY, 0 )) |
106 | ModelCloneBluePrint:SetPrimaryPartCFrame(CFrame.new( 0 , 10000 , 0 )) |
110 | Mouse.Button 1 Down:Connect( function () |
111 | if DestroyMode = = false |
113 | local Clone = Model:Clone() |
114 | Clone.Parent = game.Workspace.PlacedObject |
115 | Clone.Name = Model.Name .. "Clone" |
116 | Clone:SetPrimaryPartCFrame(CFrame.new(ModelCloneBluePrint.PrimaryPart.Position) * CFrame.Angles( 0 ,AngleY, 0 )) |
117 | local TouchDenySize = Clone.TouchDeny.Size |
118 | local TouchDenySizeX = TouchDenySize.X + ModelPrimaryPart.Size.X |
119 | local TouchDenySizeY = TouchDenySize.Y |
120 | local TouchDenySizeZ = TouchDenySize.Z + ModelPrimaryPart.Size.Z |
121 | Clone.TouchDeny.Size = Vector 3. new(TouchDenySizeX,TouchDenySizeY,TouchDenySizeZ) |
122 | elseif Mouse.Target.Parent.Parent = = game.Workspace.PlacedObject |
123 | then Mouse.Target.Parent:Destroy() |
127 | Mouse.Button 2 Down:Connect( function () |
128 | DestroyMode = not DestroyMode |