Grid placement system treating everything as 4x4 even when it's not

So basically every item has a base and a normal item has 4x4 as a base so here is what it acts like


4x4 acts as expected
However when you make it 4x2 like here, things become unexpected

Or 2x2


Or 2x6

Here is my script:

local rs = game.ReplicatedStorage
local localplayer = game.Players.LocalPlayer
local rotation = 0
local roundmodule = require(rs.ModuleScripts.Round)
game:GetService("UserInputService").InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.R then
		if rotation>=4 then
			rotation = 0
		else
			rotation = rotation+1
		end
	end
end)
game:GetService("RunService").RenderStepped:Connect(function()
	if script.Parent.Build.Value==true then
		if not game.Workspace.Temp:FindFirstChild(script.Parent.Obj.Value) then
			rs[script.Parent.Type.Value][script.Parent.Obj.Value]:Clone().Parent = game.Workspace.Temp
		else
			localplayer:GetMouse().TargetFilter = game.Workspace.Temp[script.Parent.Obj.Value]
			local xesggo = 0
			local zesggo = 0
			local xes = math.clamp(localplayer:GetMouse().Hit.p.X,game.Workspace.Grounds.Position.X-game.Workspace.Grounds.Size.X/2+game.Workspace.Temp[script.Parent.Obj.Value].PrimaryPart.Size.X/2,game.Workspace.Grounds.Position.X+game.Workspace.Grounds.Size.X/2-game.Workspace.Temp[script.Parent.Obj.Value].PrimaryPart.Size.X/2)
			local zes = math.clamp(localplayer:GetMouse().Hit.p.Z,game.Workspace.Grounds.Position.Z-game.Workspace.Grounds.Size.Z/2+game.Workspace.Temp[script.Parent.Obj.Value].PrimaryPart.Size.Z/2,game.Workspace.Grounds.Position.Z+game.Workspace.Grounds.Size.Z/2-game.Workspace.Temp[script.Parent.Obj.Value].PrimaryPart.Size.Z/2)
			if not (game.Workspace.Grounds.Position.X % 2 == 0) then
				xesggo = -1
			end
			if not (game.Workspace.Grounds.Position.Z % 2 == 0) then
				zesggo = -1
			end
			local cf = CFrame.new(roundmodule.round(xes,2)+xesggo,game.Workspace.Grounds.Position.Y+game.Workspace.Grounds.Size.Y/2+game.Workspace.Temp[script.Parent.Obj.Value].PrimaryPart.Size.Y/2,roundmodule.round(zes,2)+zesggo) * CFrame.fromEulerAnglesXYZ(0, math.rad(rotation*90), 0)
			game.Workspace.Temp[script.Parent.Obj.Value]:SetPrimaryPartCFrame(cf)
		end
	else
		localplayer:GetMouse().TargetFilter = nil
	end
end)

Yeah as you can see here the math is quite confusing for amateurs so I don’t expect an amateur to solve this problem for me but you can try

Ok so I have just found out that they do not all act like 4x4 some of them just act completely unexpected

Honestly, I don’t think anyone here will actually be able to assist you. Your issue is very specific and isn’t something of general scripting knowledge.

Each person thinks differently and trying to understand your logic would take anyone much time, I’ve always faced problems like this, where it’s not necessarily a scripting issue, rather just an issue surrounding a logic I’ve created.

The way I overcome these difficulties is to mess around with my script, possibly rewrite some parts to make sure everything’s alright. I can’t help you much further than this, rarely will someone take their time to understand your logic and operation standards to help you in such specific issue. I wish you the best of luck.

Could we see the function “roundmodule.round”?
You have code like…

roundmodule.round(xes,2)

Im assuming its rounding “xes” to a nearest multiple of two but it would be nice to know thats the case for sure.

1 Like
local module = {}
function module.round(n, int)
	return math.floor(n/int + 0.5) * int
end
return module

xes is

math.clamp(localplayer:GetMouse().Hit.p.X,game.Workspace.Grounds.Position.X-game.Workspace.Grounds.Size.X/2+game.Workspace.Temp[script.Parent.Obj.Value].PrimaryPart.Size.X/2,game.Workspace.Grounds.Position.X+game.Workspace.Grounds.Size.X/2-game.Workspace.Temp[script.Parent.Obj.Value].PrimaryPart.Size.X/2)

Temp is a folder in workspace

image

Sauruvov workspace so I found out that there is no way to just dabble I need some kinda outside help here

Here is some info: obj is a string value that represents the name of the item I want. Type is a string value that represents the name of the folder which the item is in.

based on the videos you gave the red scale is a bit low or low in width which is bad for now you can use this calculation

local Difference = RedObject.Size.X - Object.Size.X
Object.Size = Vector3.new(Difference * 2, yScale, zScale)

Basically this calculation does subtracting and sizing the object properly with it’s X and Y axis if it’s not properly formatted you can also add values if it’s an 4x4 object or an 2x2 one etc.

You can set the verticies to be the objects mesh by using my module (see vector calculations) https://github.com/EppersonJoshua/rasterizer-roblox/blob/main/Modules/VectorCalculations.lua