I’ve been working on a simple building system inspired by WTRB and just the stamper tool in general however for some reason when rounding the part’s position it keeps jittering in and out of the place where the mouse is as if it can’t decide where to go
I’ve tried looking up solutions to this but all i could find were different ways to round it none of which actually fixed anything
this is the code that gets and rounds the position of the block
function roundToGrid(value)
return math.floor(value / 4 + 0.5) * 4
end
local gridSize = 4
while task.wait() do
if ghostBlock and equipped then
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = {workspace.Players,ghostBlock}
local ray = workspace:Raycast(cam.CFrame.Position,mouse.Hit.LookVector*1000,params)
if ray and ray.Instance then
local mPos = ray.Position
local blockCF = CFrame.new(
roundToGrid(mPos.X),
roundToGrid(mPos.Y),
roundToGrid(mPos.Z)
)
blockCFrame = blockCF
print("CF: ",blockCFrame)
ghostBlock:PivotTo(blockCFrame*blockRot)
if game:GetService("RunService"):IsStudio() then
game.JointsService:SetJoinAfterMoveInstance(ghostBlock)
game.JointsService:SetJoinAfterMoveTarget(mouse.Target)
game.JointsService:ShowPermissibleJoints()
end
end
end
end
i really have no clue what I’m doing wrong as I’ve made building systems before yet when I’ve tried taking code from them to fix this issue nothing changes