Locking Pos to a 2 stud grid from FindPartOnRayWithIgnoreList

local Hit, Pos, Normal = workspace:FindPartOnRayWithIgnoreList(NewRay, {Model, Player.Character})

print(Pos.X)

Pos.X = math.floor((Pos.X / 2) + 0.5) * 2 -- Lock to a 2 stud grid

[X cannot be assigned to]

The print is returning a valid X value, so why can’t I just round it??

You need to create a new vector3 value.

As the error has implied, X cannot be assigned to.

To change values in a vector3, you have to recreate the entire vector3 iirc.

Here’s an example:

local Hit, Pos, Normal = workspace:FindPartOnRayWithIgnoreList(NewRay, {Model, Player.Character})

local posX = math.floor((Pos.X / 2) + 0.5) * 2
local newPos = Vector3.new(posX,Pos.Y,Pos.Z)

I wrote this on mobile and have not tested, but this should work.

1 Like

Huh, that seemed to work, however, even tho it’s now snapping, the model appears half in the walls

local PosX = math.floor((Pos.X / 2) + 0.5) * 2
local PosZ = math.floor((Pos.Z / 2) + 0.5) * 2
		
local NewPos = Vector3.new(PosX, Model.PrimaryPart.Position.Y, PosZ)
		
Model:SetPrimaryPartCFrame(CFrame.new(NewPos, NewPos + Normal * 15) * CFrame.Angles(-math.rad(90), 0, 0) * CFrame.new(0, Model.PrimaryPart.Size / 2, 0))

Moving on the walls


Moving it on the floor it looks good/works

Try doing the same locking on the Y axis. Other than that, I’m not sure.

Ye nah that doesn’t do anything :confused:

EDIT Nvm, found a fix

local PosX = math.floor((Pos.X / 2) + 0.5) * 2
local PosY = math.floor((Pos.Y / 2) + 0.5) * 2
local PosZ = math.floor((Pos.Z / 2) + 0.5) * 2
		
local NewPos = Vector3.new(PosX, PosY, PosZ)
		
Model:SetPrimaryPartCFrame(CFrame.new(NewPos, NewPos + Normal * 15) * CFrame.Angles(-math.rad(90), 0, 0) * CFrame.new(0, Model.PrimaryPart.Size.Y / 2, 0))

Forgot to put this back in

Model.PrimaryPart.Size.Y / 2