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
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.
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.
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.