Cough
Excuse me for the stupid title. You know what i am talking about.
Anyway, I have this pressure button that i want to go down the more mass that is on top of it. NOT the number of parts. I put this quick script together from the forum and changing it. The problem is: The button jitters. I think its a problem with the position changing, or the mass reseting every wait(), But that is necessary since the part can just go down. (Dont know what words to use here.) Could you help me? Also the GetTouchingPartsMass is not the problem. (I think)
And NO, Using TouchEnded and Touched is not reliable.
Script:
local totalMass = 0
local startingPosY = script.Parent.Position.Y
while wait() do
local function GetTouchingPartsMass(part)
local connection = part.Touched:Connect(function() end)
local resultsParts = part:GetTouchingParts()
local resultsMass = 0
local count = 0
connection:Disconnect()
for i, v in pairs(resultsParts) do
if v ~= script.Parent and not v.Anchored then
count += 1
resultsMass += v:GetMass()
end
end
--print(count)
return {mass = resultsMass, countedPart = count}
end
local totalMass = GetTouchingPartsMass(script.Parent).mass
local calc = (30*(totalMass/1500))
print(calc)
if totalMass >= 1500 then
print("Enough Pressure")
else
script.Parent.Position = Vector3.new(script.Parent.Position.X, startingPosY - calc, script.Parent.Position.Z)
end
totalMass = 0
end
