I am currently trying to create a wall placement system. I am using this to kinda get an idea of what to do, but I want to really code it myself. I am aiming for the same thing that bloxburg has or the sims when it comes to wall placement.
I am trying to also keep everything modular, so it’s easy to access and find.
This what I have for the module so far:
local drawWall = {}
local replicatedStorage = game:GetService('ReplicatedStorage')
local runService = game:GetService('RunService')
local remotes = replicatedStorage:WaitForChild('Remotes')
local placing = remotes:WaitForChild('Placing')
function roundVector(vector, unit)
return vector - Vector3.new(vector.X%unit, 0, vector.Z%unit)
end
function drawWall:StartPlacingWall(player, mouse)
local playersPlot = workspace.Plots:FindFirstChild(player.Name)
if playersPlot then
local renderStepped
local model = Instance.new('Model', playersPlot.Objects.Walls)
model.Name = 'Wall'
local pole1 = Instance.new('Part', model)
pole1.Name = 'Pole1'
pole1.Anchored = true
pole1.Transparency = 0.2
pole1.Material = Enum.Material.SmoothPlastic
pole1.Shape = 'Cylinder'
pole1.Size = Vector3.new(10, 0.4, 0.4)
local renderStepped = runService.RenderStepped:connect(function()
local mouseP = mouse.Hit.p
pole1.CFrame = CFrame.new(roundVector(mouseP + Vector3.new(0, pole1.Size.X/2, 0), 2) + Vector3.new(0.2,0,0.5))*CFrame.Angles(0, 0, math.rad(90))
end)
end
end
return drawWall
So when they click a button it starts this up, and the pole object is created, and moves with the mouse. First problem I am encountering is that it can be moved off of the players base platform. It also does not align with the grid of the base part either.
Kinda hard to see it but it’s definately not inline with the grid (should be on every intersection) the grid sizes are 1x1 too.
Next problem is when I click cancel it doesn’t go away. Local script provided below
var.Build.Activated:Connect(function()
var.Editing = true
humanoid.WalkSpeed = 0
humanoid.JumpPower = 0
var.Build.Label.Text = 'Close'
if var.Editing and not var.PlacingItem then
var.PlacingItem = true
local drawWall = require(draw.DrawWall)
drawWall:StartPlacingWall(player, mouse)
else
var.Editing = false
var.PlacingItem = false
humanoid.WalkSpeed = 16
humanoid.JumpPower = 50
var.Build.Label.Text = 'Build'
end
end)
Any help would be greatly appreciated! I’ve go over the code for the place linked above and tried it in my place, but the wall parts glitch out and I really want to try coding it in a way that I can read, as the sample code I found too confusing.