Problem with build system

Hi I have made a building system from where the mouse is and it snaps to the right location

the problem is when clicking on the block from certain directions it doesn’t let you build

I know you are suppost to make the block on the server and not to use instance.new, those are the last things im adding the the building system

1 Like

Try adding the surface normal of the mouse target times half the grid size to the mouse position, and use that as the new block position (rounded to the grid). E.g.

function getMouseNormal(): Vector3?
    local target = mouse.Target
    if not target then return end
    return target.CFrame:VectorToWorldSpace( Vector3.FromNormalId( mouse.TargetSurface ) )
end

...

    if Mouse.Target ~= nil then
		local MousePos = Mouse.Hit.Position
		MousePos += getMouseNormal() * GridSnap * 0.5
		local MousePosX = Snap(MousePos.Position.X)
		local MousePosY = Snap(MousePos.Position.Y)
		local MousePosZ = Snap(MousePos.Position.Z)
		local MousePos = Vector3.new(MousePosX, MousePosY, MousePosZ)

That way, the point that gets rounded is not at the surface of a block but the center of a part (or closer, at least). I think your issue is that your rounding logic doesn’t work correctly when a point is exactly at the edge of where one block stops and another beings, and actually there is no really good way of rounding that.

ill try it thank you also sorry for very late response i been un motivated resently

Error

Position is not a valid member of Vector3

image

1 Like

Hi, can you post the entire script in it’s current version?

1 Like

yea ok there are two part to the script one is for building a head, ill send the hole script

awdasdas dawd aw daw daw daw d

are u there???

Can you try printing the surface normal and MousePos (before snapping or adding) to verify it’s correct?

BTW here’s a function that snaps a Vector3 so you don’t need so much repetition:

local function SnapV3(v)
    return Vector3.new( Snap(v.X), Snap(v.Y), Snap(v.Z) )
end

Oh, nvm I think your problem is here:

goal.Position = Vector3.new(MousePosX - GridSnap, MousePosY, MousePosZ - GridSnap)

Your Snap function should probably be written to snap a position to the center of a grid cell, if it doesn’t already.

1 Like

I changed the goal.position and it is still not working

fixed it, it was so stupid i feel like hitting my head on a wall xD

here is what it was

goal.Position = Vector3.new(MousePosX - GridSnap, MousePosY, MousePosZ)

now

goal.Position = Vector3.new(MousePosX, MousePosY, MousePosZ)

the - gridsnap was offsetting the block, it should never of been there and i feel very stupid rn xD

1 Like

Here is the full updated code if u want to use

if Mouse.Target ~= nil then
		local MousePos = Mouse.Hit.Position
		MousePos += getMouseNormal() * GridSnap * 0.5
		local MousePosX = Snap(MousePos.X)
		local MousePosY = Snap(MousePos.Y)
		local MousePosZ = Snap(MousePos.Z)
		local MousePos = Vector3.new(MousePosX, MousePosY, MousePosZ)
		
		local HRPSNAPX = Snap(HRP.Position.X)
		local HRPSNAPY = Snap(HRP.Position.Y)
		local HRPSNAPZ = Snap(HRP.Position.Z)
		local HRPSNAP = Vector3.new(HRPSNAPX, HRPSNAPY, HRPSNAPZ)
		
		local TORSOSNAPX = Snap(Torso.Position.X)
		local TORSOSNAPY = Snap(Torso.Position.Y)
		local TORSOSNAPZ = Snap(Torso.Position.Z)
		local TORSOSNAP = Vector3.new(TORSOSNAPX, TORSOSNAPY, TORSOSNAPZ)
		
		local Distance = (HRPSNAP - MousePos).magnitude
		local StudsOfReach = GridSnap * MBD
		
		if Distance < StudsOfReach then
			
			if Mouse.Target.Name == Floor then
				
				
				local part = Instance.new("Part")
				part.Position = Vector3.new(MousePosX, MousePosY - (GridSnap / 2), MousePosZ)
				part.Size = Vector3.new(GridSnap, 0, GridSnap)
				part.Anchored = true
				part.Parent = game.Workspace

				local goal = {}
				goal.Size = Vector3.new(GridSnap, GridSnap, GridSnap)
				goal.Position = Vector3.new(MousePosX, MousePosY, MousePosZ)

				local tweenInfo = TweenInfo.new(0.1)

				local tween = TweenService:Create(part, tweenInfo, goal)

				tween:Play()				
				
				print("BUILT AT MOUSE")
				
			else
				
				
				local part = Instance.new("Part")
				part.Position = Vector3.new(MousePosX, MousePosY - (GridSnap / 2), MousePosZ)
				part.Size = Vector3.new(GridSnap, 0, GridSnap)
				part.Anchored = true
				part.Parent = game.Workspace

				local goal = {}
				goal.Size = Vector3.new(GridSnap, GridSnap, GridSnap)
				goal.Position = Vector3.new(MousePosX, MousePosY, MousePosZ)

				local tweenInfo = TweenInfo.new(0.1)

				local tween = TweenService:Create(part, tweenInfo, goal)

				tween:Play()
				print(Mouse.Hit.Position)
				print(MousePos)

				
			end
			
		end
		
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.