Unexplained offset

I’ve got a script to place a board with pins locally, yet there is some offset as seen by this:


The offset is not consistent and fluctuates a lot.

Here’s my entire local script:

local tilemodel = game.ReplicatedStorage.models.tile
local camera = workspace.CurrentCamera
local lplr = game.Players.LocalPlayer
local mouse = lplr:GetMouse()
local e = false
local p
local start = Vector3.new(0,0,0)

local bFolder = workspace.Board

local rparams = RaycastParams.new() 
rparams.FilterType = Enum.RaycastFilterType.Include
rparams.FilterDescendantsInstances = {workspace.Baseplate}

local temporaryParts = {}
local function RayCam()
	return workspace:Raycast(camera.CFrame.Position,mouse.Origin.LookVector*1000)
end

local function RoundVector(v:Vector3,increment)
	return
		Vector3.new(
			math.floor(v.X/increment)*increment,
			math.floor(v.Y/increment)*increment,
			math.floor(v.Z/increment)*increment
		)
end

local function Round(v,i)
	return math.floor(v/i)*i
end


mouse.Button2Down:Connect(function()
	if not e then
		e = true
		p = Instance.new('Part')
		p.Size = Vector3.new(1,1,1)
		p.Anchored = true
		p.Parent = workspace
		p.Transparency = .7
		p.Material = Enum.Material.Plastic
		start = RoundVector(RayCam().Position,4)
	else
		e = false
		p:Destroy()
		local ray = RayCam()
		if ray then
			local pos = ray.Position
			
			local minx = math.min(pos.X,start.X)
			local maxx = math.max(pos.X,start.X)
			
			local minz = math.min(pos.Z,start.Z)
			local maxz = math.max(pos.Z,start.Z)
			
			for x = 1, (maxx-minx)/2 do
				for z = 1, (maxz-minz)/2 do
					task.wait()
					local newTile = tilemodel:Clone()
					newTile.Parent = bFolder
					
					local cord = 
						Vector3.new(
							minx + 1 + (x-1)*2,
							2,
							minz + 1 + (z - 1)*2
						)
					newTile:PivotTo(CFrame.new(cord))
				end
			end
			
		end
	end
end)

mouse.Move:Connect(function()
	if e then
		local ray = RayCam()
		if ray then
			local xdif = math.abs(Round(ray.Position.X,4) - Round(start.X,4))
			local zdif = math.abs(Round(ray.Position.Z,4) - Round(start.Z,4))
			
			local xavg = Round((ray.Position.X+start.X)/2,2)
			local zavg = Round((ray.Position.Z+start.Z)/2,2)
			
			if p and e then 
				p.Position = Vector3.new(xavg,1,zavg)
				p.Size = Vector3.new(xdif,1,zdif)
			end
		end
	end
end)

First thing is to just start creating parts at the mouse position every second. See if there is any error there, then report back and we can give you more help.

That was my previous approach, it ended up being very laggy and caused my studio to crash a few times

Okay, then attach debris service to the parts.
It can be extremely short life, you just need to see somehow.

fixed the issue, a single value wasn’t rounded and that causes a weird offset as other values were rounded

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