Adding vector3 value to part size make weird value

Hello, People I’m making a hitbox for my object throwing system, the problem is with the size of the hitbox that I am spawning and welding it to the object, I checked if the part that I’m throwing is inside a model or not so that I can then get the appropiate size for the hitbox and make it a bit bigger than the object. It works fine for part inside model but for a normal basepart when I try making the size bigger it just broke and gave me weird values

function HitboxModule.VelocityBased(part, damage, minVelocity, deb)
	
	print(part.Name)
	print(part.size)
	
	local size = part.Size + Vector3.new(1, 1, 1)
	
	if part.Parent:IsA("Model") then
		
		local _ ,boundingBox = part.Parent:GetBoundingBox()
		
		size = boundingBox + Vector3.new(1, 1, 1)
		
	end
	
	print(size)
	
	if size then
		
		local hitbox = Instance.new("Part")
		hitbox.Anchored = false
		hitbox.CanCollide = false
		hitbox.Massless = true
		hitbox.Size = size
		hitbox.CFrame = part.CFrame
		hitbox.Color = Color3.fromRGB(255, 0, 0)
		hitbox.Parent = part

		if deb == false or deb == nil then
			hitbox.Transparency = 1
		else
			hitbox.Transparency = 0.5
		end

		local weld = Instance.new("WeldConstraint")
		weld.Enabled = true
		weld.Parent = hitbox
		weld.Part0 = hitbox
		weld.Part1 = part
		
	end
	
end

Here’s what its printing

image

Are you sure that adding the vector3 is the problem? It seems to me that the issue would be the bounding box being large (indicating that the objects within part.Parent are spread out over an area that is 2048x2048

Oh, you’re right, somehow the part that is not inside the model make it through the :IsA(“Model”) statement. The part.Parent.ClassName I’m printing said its a workspace and not a model

uh the size variable at first its a vector value and then uh ur adding another size with another vector, uh idk if it gonna work im very dumb

Yeah, the size thing works fine now but I just can’t figure out why the part that is not in the model still get through the part.Parent:IsA(“Model”) statement that make it scale to 2048x2048. Idk what I did wrong

is the part parented to another model, also can u explain where the hitbox clones i kinda dont get it

a parts size can only be 2048 in each axis
so the biggest part possible is one of size (2048, 2048, 2048)

calling workspace:GetBoundingBox()
gives me a size of (2048, 252, 2048)
when removing the baseplate it gives (2044, 252, 2044)
Not entirely sure what it’s basing that size off of, as there are no instances going that far

when your part is inside the workspace, part.Parent == workspace, and therefore you get that result

EDIT: In addition, workspace, is indeed a model. Apparently.
image

You can use the ClassName property instead of :IsA()

Ah, I see. Didn’t think workspace would be a model. Now I get why the part get through the if statement. Thank you

1 Like

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