Need help scripting a player scale

Hello, fellow scripters! I have a task on my hands that I need some help with. I am attempting to grab the mass of a player’s entire body and output its number onto a scale. The code I currently have is using a touching event to grab the mass of every part of the player’s body but it’s not seeming to work. Could someone give me a hand? Thanks to those who can help!

Here is the code:

local Pad = script.Parent
local ScaleText = script.Parent.Parent.Numbers.SurfaceGui.TextBox.Text
local Touching = Pad.CanTouch
ScaleText = "0" .. "LBS"

Touchpad = Pad.Touched:Connect(function(hit)
	local LFoot = hit.Parent.LeftFoot.Mass
	local LHand = hit.Parent.LeftHand.Mass
	local LLowerArm = hit.Parent.LeftLowerArm.Mass
	local LLowerLeg = hit.Parent.LeftLowerLeg.Mass
	local LUpperArm = hit.Parent.LeftUpperArm.Mass
	local LUpperLeg = hit.Parent.LeftUpperLeg.Mass
	local LowerTorso = hit.Parent.LowerTorso.Mass
	local RFoot = hit.Parent.RightFoot.Mass
	local RHand = hit.Parent.RightHand.Mass
	local RLowerArm = hit.Parent.RightLowerArm.Mass
	local RLowerLeg = hit.Parent.RightLowerLeg.Mass
	local RUpperArm = hit.Parent.RightUpperArm.Mass
	local RUpperLeg = hit.Parent.RightUpperLeg.Mass
	local UpperTorso = hit.Parent.UpperTorso.Mass
	local Head =hit.Parent.Head.Mass
	print("Calculating weight...")
	local weight = LFoot + LHand + LLowerArm + LLowerLeg + LUpperArm + LUpperLeg + LowerTorso + RFoot + RHand + RLowerArm + RLowerLeg + RUpperArm + RUpperLeg + UpperTorso + Head
	ScaleText = weight .. "LBs"
	wait(5)
	ScaleText = "0" .. "LBS"
	wait(2)
end)

Here is the object:
Screen Shot 2021-10-10 at 7.51.46 PM

How exactly is it not working? Is it throwing an error, is there a logical problem?

I also see that you’re just changing the variable value and not actually updating the property of the text element, this could maybe what you’re talking about?
Fix:
script.Parent.Parent.Numbers.SurfaceGui.TextBox.Text = weigth … “LBs”

Side-note: I get a feeling this could also be reduced by iterating the hit.Parent and maybe use a blacklist if needed?

local Pad = script.Parent
local Scale = Pad.Parent.Numbers.SurfaceGui.TextBox
Scale.Text = "0".."LBS"

local Debounce = true

Pad.Touched:Connect(function(hit)
    local Humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
    local TotalWeight = 0

    if Debounce and Humanoid then
        Debounce = false
        print("Calculating weight...")

        for _, Child in ipairs(hit.Parent:GetChildren()) do
            if Child:IsA("BasePart") then
                TotalWeight += Child.Mass
            end
        end

        Scale.Text = math.round(TotalWeight).."LBS"
        task.wait(5)
        Scale.Text = "0".."LBS"

        task.wait(2)
        Debounce = true
    end
end)

looked like you were trying to get every part, so I used a for loop instead
also you can’t change the text if you set the text as the variable
you have to do Object.Text = String

Thanks so much for the clarification! I read over your script and realized that changing the text using a variable wouldn’t work. Also, a debug was needed to make sure the pad wouldn’t keep detecting steps. Well done! You’re the man!

1 Like