Grid system un-aligning when rotating(NOT SOLVED)

Issue:
https://gyazo.com/81cde2c53eda2c3e33d62d450562b06f
Happens at 0:05 You can see the unalignment.
Relevant code:

elseif BuildMode == true and key.UserInputType == Enum.UserInputType.MouseButton1 then
		local parttheir = false
		if  mouse.Hit.Y >= plot.Position.Y + plot.Size.Y/2.0001  then
			local pos = Vector3.new(math.floor(mouse.Hit.X/grid + 0.5)*grid,(plot.Position.Y*2)+(part.Size.Y/2),math.floor(mouse.Hit.Z/grid + 0.5)*grid) + add
			for i,v in pairs(game.Workspace:GetChildren()) do
				if v:IsA("UnionOperation") and v.Position.X == pos.X and v.Position.Z == pos.Z and not v:FindFirstChild("Value")  then
					parttheir = true
				end
			end
			if parttheir == false and mouse.Target == plot then
				game.ReplicatedStorage.BuildEvent:FireServer(part.Name,pos,currenty)
				end
		end

ServerCode

game.ReplicatedStorage.BuildEvent.OnServerEvent:Connect(function(plr,part,pos,orientationy)
	local Part = game.ReplicatedStorage:FindFirstChild(part):Clone()
	Part.Parent = game.Workspace
	Part.Position = pos
	Part.Orientation = Vector3.new(Part.Orientation.X,orientationy,Part.Orientation.Z)
	Part:FindFirstChild("Value"):Destroy()
end)
game.ReplicatedStorage.RemoveEvent.OnServerEvent:Connect(function(plr,poopscoopernumber1)
	for i,v in pairs(game.Workspace:GetChildren()) do
		if v:IsA("UnionOperation") and v.Position == poopscoopernumber1 and not v:FindFirstChild("Value") then
			v:Destroy()
		end
	end
end)

Entire thing

local tw = game:GetService("TweenService")
local mouse = game.Players.LocalPlayer:GetMouse()
local UIS = game:GetService("UserInputService")
local plot = game.Workspace:WaitForChild("Plot")
local gui = game.Players.LocalPlayer.PlayerGui.ScreenGui
local part
local BuildMode = false
local db = false
local Texture
local currenty = 0
local grid = 6
local rendersteps = game:GetService("RunService")
local add 
local wasd
UIS.InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.B and BuildMode == false then
		gui.Building.FurnitureGui.Close.MouseButton1Click:Connect(function()
			for i,v in pairs(gui.Building.FurnitureGui:GetChildren()) do
				v.Visible = false
			end
			for i,v in pairs(gui.Building:GetChildren()) do
				if v:IsA("TextButton") then
					v.Visible = true
				end
			end
		end)
		BuildMode = true
		Texture = game.ReplicatedStorage.Texture:Clone()
		Texture.Parent = plot
		gui.Building.Visible = true
		for i,v in pairs(gui.Building:GetChildren()) do
			if v:IsA("TextButton") then
				v.Visible = true
			end
		end
		gui.Building.Furniture.MouseButton1Click:Connect(function()
			for i,v in pairs(gui.Building:GetChildren()) do
				if v:IsA("TextButton") then
					v.Visible = false
				end
			end
			for i,v in pairs(gui.Building.FurnitureGui:GetChildren()) do
				v.Visible = true
				v.MouseButton1Click:Connect(function()
					if part then
						part:Destroy()
					end
					if game.ReplicatedStorage:FindFirstChild(v.Name) then
						part = game.ReplicatedStorage:FindFirstChild(v.Name):Clone()
						part.Transparency = 0.3
						currenty = part.Orientation.Y
						part.Parent = game.Workspace
						mouse.TargetFilter = part
						end
				end)
			end
		end)
		rendersteps.RenderStepped:Connect(function()
			if mouse.Target == plot and mouse.Hit.Y >= plot.Position.Y + plot.Size.Y/2.0001 and part then
				if part:FindFirstChild("Value").Value == true then
					add = part.CFrame.LookVector * grid/2
				else
					add = Vector3.new()
				end
				tw:Create(part,TweenInfo.new(0.25),{Position = Vector3.new(math.floor(mouse.Hit.X/grid + 0.5)*grid,(plot.Position.Y*2)+(part.Size.Y/2),math.floor(mouse.Hit.Z/grid + 0.5)*grid)+add}):Play() 
			end
		end)
	elseif BuildMode == true and key.KeyCode == Enum.KeyCode.B  then
		BuildMode = false
		gui.Building.Visible = false
		part:Destroy()
		Texture:Destroy()
		for i,v in pairs(gui.Building.FurnitureGui:GetChildren()) do
			v.Visible = false
		end
	elseif BuildMode == true and key.KeyCode == Enum.KeyCode.R then
		if db == false then
			db = true
			currenty = part.Orientation.Y + 90
			tw:Create(part,TweenInfo.new(0.25),{Orientation = part.Orientation + Vector3.new(0,90,0)}):Play()
			task.delay(0.25, function()
				db = false
			end)
		end
	elseif BuildMode == true and key.UserInputType == Enum.UserInputType.MouseButton1 then
		local parttheir = false
		if  mouse.Hit.Y >= plot.Position.Y + plot.Size.Y/2.0001  then
			local pos = Vector3.new(math.floor(mouse.Hit.X/grid + 0.5)*grid,(plot.Position.Y*2)+(part.Size.Y/2),math.floor(mouse.Hit.Z/grid + 0.5)*grid) + add
			for i,v in pairs(game.Workspace:GetChildren()) do
				if v:IsA("UnionOperation") and v.Position.X == pos.X and v.Position.Z == pos.Z and not v:FindFirstChild("Value")  then
					parttheir = true
				end
			end
			if parttheir == false and mouse.Target == plot then
				game.ReplicatedStorage.BuildEvent:FireServer(part.Name,pos,currenty)
				end
		end
	elseif BuildMode == true and key.UserInputType == Enum.UserInputType.MouseButton2 then
		local pos = Vector3.new(math.floor(mouse.Hit.X/grid + 0.5)*grid,(plot.Position.Y*2)+(part.Size.Y/2),math.floor(mouse.Hit.Z/grid + 0.5)*grid) + add
		print("ooga")
		for i,v in pairs(game.Workspace:GetChildren()) do
			if v:IsA("UnionOperation") and v.Position.X == pos.X and v.Position.Z == pos.Z and not v:FindFirstChild("Value") then
				print("Poop")
				game.ReplicatedStorage.RemoveEvent:FireServer(v.Position)
			end
		end
	end
end)

Thank you for help in advance. You can ask me any questions and I will respond to you.

I haven’t read the code but in advance, it may be because you’re placing it while it’s still interpolating/tweening.

Edit: After taking a little look on your code that doesn’t seem to be the issue. Try making the code easier to read (structuring it better and separating more, add comments, give more useful names to stuff aswell, etc) and use functions for stuff you’ll need to do more than once or twice like calculating the position. I gotta go right now, hopefully that helps you find the issue.

1 Like

I don’t think making the code organized will fix it.

1 Like

It wont fix it, but itll help with others and with you fixing it (you dont have to tho)

1 Like

But it’ll help you find the issue, and avoid future ones

The code is indeed very hard to read

My guess would be to remove this add at the end of the line, it seems like it is adding a value from the tweening in the RenderStepped… LookVector changes as the part rotates so maybe that could be why?

Idk what the add does but um, if it is important and if that is indeed the issue, you’ll have to change how it is calculated

I’ll try that I’ll l u know if it works Tommorow

I don’t think that’s the issue. It still doesn’t wwork

someone help please ive asked like 3 ppl and they have no idea

I’m going to give you some advice.
Don’t use Vector3s (besides from mouse hit) for a grid placement system. They’re unreliable if you want to add rotation.

Use CFrames. You can still use the relevant components of the Vector3 (X/Y/Z) and on top of that add Angles/Rotation to your CFrame with CFrame.Angles.

Using Vector3s for it just over complicates it since you’re now relying on two different properties you’d need to compensate for with each other.

Example: (this is from my own placement system which works reliably with rotation, but I’ve removed the calculations for the Delta variables.)

                    local GridSpace = CFrame.new(
						Round(DeltaHitX, 1),
						PhysicalTop + PrimarySize.Y,
						Round(DeltaHitZ, 1)
					)
					PlacementObject:SetPrimaryPartCFrame(GridSpace * CFrame.Angles(0, math.rad(Rotation), 0))

ill convert to cframe then thanks for the advice ill let you know if it fixes the issue or not.