This code makes a wall.
It uses magnitude to create the size (so it stretches from point 1 to point 2)
except since roblox is weird, it scales magnitude in both directions
for instance if the part was 5 studs away
the wall scales in both directions of Z. Hope that makes sense
local m = game.Players.LocalPlayer:GetMouse()
local debounce = false
local Position = nil
m.Button1Down:connect(function(k)
Position = m.Hit.Position
wait(1)
end)
m.Button1Up:connect(function(k)
local Position2 = m.Hit.Position
local wall = Instance.new("Part")
wall.Position = Position
wall.Parent = workspace
wall.Anchored=true
local magnitude = (wall.Position-Position2).Magnitude
wall.Size = Vector3.new(0.5,1,magnitude)
while true do
wall.CFrame = CFrame.new(wall.Position, Position2)
wait()
end
end)
dont multiply it i mean add it to a specific vector3 axis like wall.Position.X + wall.Size.X/2
or whatever axis you need it to be
oh yeah like @TheSenorDuck said i made a mistake, get a particular axis for the size of the wall to be added to a specific axis on the position vector of the wall.
From what I understand you want to make a wall from the position where you pressed down your mouse to the position where you let go of your mouse
To make the wall face from p1 to p2 you just do wall.CFrame = CFrame.lookAt(p1, p2) and then you multiply that cframe by CFrame.new(0, 0, -wall.Size.Z / 2) to move the wall forward by half of the wall’s length so it’s between p1 and p2. For the size it’s just the magnitude between p1 and p2 (you have that correct for the most part)
Also I’m not sure why you have a while loop in there
One last question
How do I make it not face into the floor?
Since cframe:Lookat() uses 3D (XYZ when I want it to only be XZ) it can also face downwards towards the point.
You could raycast down from the midpoint of “Position” and “Position2” and set their Y coordinate to the raycast’s Y coordinate. Or just use the lowest Y coordinate out of the two positions if you’re building on flat terrain
I don’t know how you want your wall placement to behave so I don’t know the best way to help