I want to make a big part within 3 parts: X, Y, and Z parts. The problem is that (it seems) like it is not subtracting correctly. I have no idea what’s wrong.
Code (Sorry if it seems bad, I’m dumb when it comes to Vector3):
local part = Instance.new("Part")
local coordinates = game.Workspace:WaitForChild("Coordinates")
local setToPositive = function(coordinate)
if coordinate < 0 then
local stringed = tostring(coordinate)
local newnum = string.gsub(stringed, "-", " ", 1)
local returned = tonumber(newnum)
return {returned, true}
else
return {coordinate, false}
end
end
local XofX = coordinates:WaitForChild("X").Position.X
local finalXofX = (setToPositive(XofX)[1])
local YofX = coordinates:WaitForChild("X").Position.Y
local finalYofX = (setToPositive(YofX)[1])
local ZofX = coordinates:WaitForChild("X").Position.Z
local finalZofX = (setToPositive(ZofX)[1])
local newVector3ofX = Vector3.new(finalXofX, finalYofX, finalZofX)
local XofZ = coordinates:WaitForChild("Z").Position.X
local finalXofZ = (setToPositive(XofZ)[1])
local ZofZ = coordinates:WaitForChild("Z").Position.Z
local finalZofZ = (setToPositive(ZofZ)[1])
local newVector3ofZ = Vector3.new(finalXofZ, finalYofX, finalZofZ)
local XofY = coordinates:WaitForChild("Y").Position.X
local finalXofY = (setToPositive(XofY)[1])
local YofY = coordinates:WaitForChild("Y").Position.Y
local finalYofY = (setToPositive(YofY)[1])
local newVector3ofY = Vector3.new(finalXofY, finalYofY, finalZofX)
local stringed
local newnum
local returned
local newXofX = Vector3.new(newVector3ofX.X, 0, 0)
local newXofZ = Vector3.new(newVector3ofZ.X, 0, 0)
local xPos = (newXofX - newXofZ)/2
if xPos.X < 0 then
xPos = (newXofZ-newXofX)/2
end
local XSize = (newVector3ofX - newVector3ofZ).Magnitude
if (setToPositive(XofX)[2]) == true or (setToPositive(XofZ)[2]) == true then
stringed = tostring(xPos.X)
newnum = string.gsub(stringed, " ", "-", 1)
returned = tonumber(newnum)
xPos = Vector3.new(returned, 0, 0)
end
local newYofX = Vector3.new(0, newVector3ofX.Y, 0)
local newYofY = Vector3.new(0, newVector3ofY.Y, 0)
local yPos = (newYofX - newYofY)/2
if yPos.Y < 0 then
yPos = (newYofY-newYofX)/2
end
local YSize = (newVector3ofX - newVector3ofY).Magnitude
if (setToPositive(YofX)[2]) == true or (setToPositive(YofY)[2]) == true then
stringed = tostring(yPos.Y)
newnum = string.gsub(stringed, " ", "-", 1)
returned = tonumber(newnum)
yPos = Vector3.new(0, returned, 0)
end
local newZofX = Vector3.new(0, 0, newVector3ofX.Z)
local newZofZ = Vector3.new(0, 0, newVector3ofZ.Z)
local zPos = (newZofX-newZofZ)/2
if zPos.Z < 0 then
zPos = (newZofZ-newZofX)/2
end
local ZSize = (newVector3ofX - newVector3ofZ).Magnitude
if (setToPositive(ZofX)[2]) == true or (setToPositive(ZofZ)[2]) == true then
stringed = tostring(zPos.Z)
newnum = string.gsub(stringed, " ", "-", 1)
returned = tonumber(newnum)
zPos = Vector3.new(0, 0, returned)
end
local FINALVECTOR = Vector3.new(xPos.X, yPos.Y, zPos.Z)
local SIZE = Vector3.new(XSize, YSize, ZSize)
part.Position = FINALVECTOR
part.Size = SIZE
part.Parent = game.Workspace
bro stop ignoring my post

