Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Dividing an object's volume by .2^3?

local b = .2 * .2 * .2

script.Parent.Touched:connect(function(hit)
	if hit.Name == "Scrap" and not hit.Size == Vector3.new(.2, .2, .2) then
		hitmass = hit.Size.X * hit.Size.Y * hit.Size.Z
		a = hitmass / b
		for i = 1, tonumber(a) do
			dust = Instance.new("Part", game.Workspace)
			dust.Size = Vector3.new(.2, .2, .2)
			dust.Position = hit.Position
			dust.BrickColor = hit.BrickColor
		end
		hit:Destroy()
	end
end)

I'm confused. I've never done this much math in Lua. No output.

1 answer

✓ Accepted answer

tonumber is not necessary in this case. a is already a number.

hitmass is being computed correctly, but just to let you know, GetMass actually is a property of parts (although I suppose the density of parts with materials may be subject to change, so your volume approach is just fine too!)

Parts by default do not have a FormFactor of Custom, so they will reject the size Vector3.new(0.2,0.2,0.2). You need to set the FormFactor to Custom before setting the size to that.

Everything else is fine, perhaps not quite what you're looking for, because all of the parts will be smashed together in the center of the part.

A separate warning: 0.2 cannot be losslessly stored in binary. This means that there is a chance that Vector3.new(.2,.2,.2) may not be equal to an apparently equal vector. While it will probably be okay, it's better to allow very small tolerances (but obviously more complicated).

In this particular case, it would probably be better to reference the object's length or volume instead, anyway, which would be safer, and, for instance, not break extremely tiny (or smaller dust) up more: hit.Size.magnitude < 0.35

This discussion is preserved as it was. New answers, comments, and votes are closed.