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