How would I Make a Balancing Scale System

Hey there, I am in need of some help as I have spent a few days on trying to make a Balancing Scale that is used to measure two objects weight/mass.

What I am trying to do is make the pans adjust depending on the weight/mass of the object like in the image.

MY PROGRESS
I found a balancing scale in the toolbox and I created a code I found from an article for a balancing scale in C and converted it to Lua.

The code:

-----Variables------
-----Variables------
local BalancingScale = script.Parent
local Pan1 = BalancingScale.Pan1
local Pan2 = BalancingScale.Pan2

local PansTable = {Pan1, Pan2}


-----Create table to store weight---
local MassTable = {}
local TotalMass = 0


------Create a function to determine the weight of the Items----
local function DetermineMass(Item)
	local ItemMass = Item:GetMass()
	TotalMass =  TotalMass + ItemMass

end

DetermineMass(BalancingScale.HeavyPart)

-----Loop through the weight on the Scale----
while task.wait(1) do
	
	----Get the Center of Mass for the Weighted Objects
	local COM
	
	for item, itemMass in pairs(MassTable) do
		COM =  CFrame.new( (item.Position + item.CFrame.lookVector * item.Size.Z / 2) * itemMass)
			
	end
	
	----Place the Torque Physics on Scale-----
	for i, Pan in pairs(PansTable) do
		
		local Offset = Pan.Position - COM.Position
		local Torque = Offset:Cross(Vector3.new(0,0,-1)) * Offset.Magnitude
		Pan.AngularVelocity.AngularVelocity = Torque * (5 / TotalMass)
		
	end
	
end

PROBLEM
When I test the game, it still doesn’t seem to work or move and the pans don’t move at all. I am currently stuck on this

maybe its the typo of 'Density`

I can’t believe I didn’t see this, thanks, I will try it out

That didn’t work sadly, I however changed the code to get the item’s mass instead but still no luck

tbh this code doesnt make any sense

you should just use roblox physics no need for a script

1 Like

I did try and replicate Roblox Physics through the AngularVelocity Constraint, could you go into more detail?

1 Like

put an attachment at the top of a verticle stick, put an attachment in the middle of a horizontal stick, connect them with a hinge constraint. then attach your pans with ropes or something. no need for scripts

Such an easier answer than all that research :sweat_smile:, thanks for taking the time to help!

2 Likes

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