How to Make A Grid for a building System?

Hello Everyone i hope you have a Great day so i made a building system recently and I wanted to make a grid for it, it is quite hard for me since i don’t know how to make a grid at all i would be thankful if anyone could help!

Code(It is very messy):

wait(3)
local Player = game.Players.LocalPlayer
local BuildGuide  = Player.PlayerGui:WaitForChild("BuildGuide")
local BuildGui  = Player.PlayerGui:WaitForChild("BuildGui")
local mouse = Player:GetMouse()
local Angles = 0
local userinput = game:GetService("UserInputService")
for i,v in pairs(script.Parent:GetChildren()) do
if v:IsA("ImageButton") or v:IsA("TextButton") then
v.MouseButton1Click:Connect(function()
BuildGui.Enabled = false
BuildGuide.Enabled = true
local clone 
clone = game.ReplicatedStorage.Builder:FindFirstChild(v.Value.Value):Clone()
clone.Parent = workspace
mouse.TargetFilter = clone
clone.Name = "Clonething"..Player.Name
if clone:IsA("Model") then
for i,meow in pairs(clone:GetDescendants()) do
		if meow:IsA("BasePart") then
			meow.CanCollide = false
			end
end
			else
	clone.CanCollide = false
end
if userinput.TouchEnabled == true then
BuildGuide.Frame.Rotate.TextLabel.Visible = false
BuildGuide.Frame.Cancel.TextLabel.Visible = false
BuildGuide.Frame.Done.Visible = true
BuildGuide.Frame.TextLabel.Visible = false
BuildGuide.Frame.Done.MouseButton1Click:Connect(function()
print(v.Value.Value)
if script.Parent.PlotMode.Value == true then
if mouse.Target.Name == "Place" and mouse.Target.Parent.Player.Value == Player.Name then
if Player.leaderstats.Money.Value >= v.Money.Value then	
if clone:IsA("Model") then
game.ReplicatedStorage.Build:FireServer(v.Value.Value,clone.PrimaryPart.CFrame,v.Money.Value,1)
else
	game.ReplicatedStorage.Build:FireServer(v.Value.Value,clone.CFrame,v.Money.Value,1)
end
clone:Destroy()
clone = nil
script.Parent.Parent.Parent.BuildGuide.Enabled = false
end
end
				else if mouse.Target:IsA("Part") or mouse.Target:IsA("BasePart") then
						if Player.leaderstats.Money.Value >= v.Money.Value then	
if clone:IsA("Model") then
game.ReplicatedStorage.Build:FireServer(v.Value.Value,clone.PrimaryPart.CFrame,v.Money.Value,1)
else 
	game.ReplicatedStorage.Build:FireServer(v.Value.Value,clone.CFrame,v.Money.Value,1)
end	
end

end
end
end)
			else
mouse.Button1Down:Connect(function()
print(v.Value.Value)
if script.Parent.PlotMode.Value == true then
if mouse.Target.Name == "Place" and mouse.Target.Parent.Player.Value == Player.Name then
if Player.leaderstats.Money.Value >= v.Money.Value then	
if clone:IsA("Model") then
game.ReplicatedStorage.Build:FireServer(v.Value.Value,clone.PrimaryPart.CFrame,v.Money.Value,1)
else
	game.ReplicatedStorage.Build:FireServer(v.Value.Value,clone.CFrame,v.Money.Value,1)
end
clone:Destroy()
clone = nil
BuildGuide.Enabled = false
end
end
				else if mouse.Target:IsA("Part") or mouse.Target:IsA("BasePart") then
						if Player.leaderstats.Money.Value >= v.Money.Value then	
if clone:IsA("Model") then
game.ReplicatedStorage.Build:FireServer(v.Value.Value,clone.PrimaryPart.CFrame,v.Money.Value,1)
else 
	game.ReplicatedStorage.Build:FireServer(v.Value.Value,clone.CFrame,v.Money.Value,1)
end	
end

end
end
end)	
end

mouse.Move:Connect(function()
if clone then
mouse.TargetFilter = clone
if clone:IsA("Model") then
	clone:SetPrimaryPartCFrame(CFrame.new(mouse.Hit.p+Vector3.new(0,clone.Hitbox.Size.Y/2,0))*CFrame.Angles(0,math.rad(Angles),0))
	mouse.TargetFilter = clone
if script.Parent.PlotMode.Value == true then
	
if mouse.Target.Name == "Place" and mouse.Target.Parent.Player.Value == Player.Name then

clone.Hitbox.Transparency = 0.5
clone.Hitbox.BrickColor = BrickColor.new("Bright green")
					else
			clone.Hitbox.Transparency = 0.5
	clone.Hitbox.BrickColor = BrickColor.new("Really red")
	
end
else  if script.Parent.PlotMode.Value == false then
if mouse.Target:IsA("Part") or mouse.Target:IsA("BasePart") then
	clone.Hitbox.Transparency = 0.5
clone.Hitbox.BrickColor = BrickColor.new("Bright green")
					else
			clone.Hitbox.Transparency = 0.5
	clone.Hitbox.BrickColor = BrickColor.new("Really red")
	end
end
end
end
if clone:IsA("Part") or clone:IsA("MeshPart") or clone:IsA("UnionOperation") then
clone.CFrame = CFrame.new(mouse.Hit.p+Vector3.new(0,clone.Size.Y/2,0))*CFrame.Angles(0,math.rad(Angles),0)
if script.Parent.PlotMode.Value == true then
if mouse.Target.Name == "Place" and mouse.Target.Parent.Player.Value == Player.Name then
clone.BrickColor = BrickColor.new("Bright green")
					else
			
	clone.BrickColor = BrickColor.new("Really red")
end
else if mouse.Target:IsA("Part") or mouse.Target:IsA("BasePart") then
	clone.BrickColor = BrickColor.new("Bright green")
					else
			
	clone.BrickColor = BrickColor.new("Really red")	
	end
	
end
end
BuildGuide.Frame.Cancel.MouseButton1Click:Connect(function()
clone:Destroy()
clone = nil	
BuildGuide.Enabled = false
end)
userinput.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Q then
clone:Destroy()
clone = nil
BuildGuide.Enabled = false
end
end)
Player.Character.Humanoid.HealthChanged:Connect(function()
if Player.Character.Humanoid.Health <= 0 then
clone:Destroy()
clone = nil	
end
end)
end
end)
end)
end
BuildGuide.Frame.Rotate.MouseButton1Click:Connect(function()
Angles = Angles +2
end)
userinput.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.R then
Angles = Angles +2
end
end)

end

Have you considered this?

I already figured that out but i mean for the Moving you know when you
move your Object

Not sure what you mean, is it something like this?

Yes this what i mean

gif3

you see how here it is not moving freely

how do i make something like this is in my building system script

I would recommend rounding the position to nearest 4 or something like that to make a grid system.

Here is an example of how to round a number to nearest multiple.

1 Like

Thank you So Much!
Hope you have a great day :smiley:

1 Like