How do I perform arithmetic on 3 numbervalues but for multiple sets of them

I’m trying to make the price value (numbervalue) of buttons in my tycoon game change depending on how many players are in the game by doing a numbervalue1 = numbervalue2 * numbervalue3 method through using the getdescendants function but it’s not working.

	local descendants = game.Workspace.Buttons:GetDescendants()
	for index, dprice in pairs(descendants) do
		if dprice.Name == "Price" then
			for index2, drealprice in pairs(descendants) do
				if drealprice.Name == "RealPrice" then
					drealprice = dprice * pricemultiplier
				end
			end
		end
	end

Any help would be greatly appreciated!

It would be useful if you could post a picture of the exact hierarchy inside these buttons, to get a better understanding of what you are trying to achieve.

edit to clarify: buttons model located in workspace
image
image
This is what’s causing the error btw:

drealprice = dprice * pricemultiplier

Since these are value instances, you have to add “.Value”
It should look like this then:

local descendants = game.Workspace.Buttons:GetDescendants()
	for index, dprice in pairs(descendants) do
		if dprice.Name == "Price" then
			for index2, drealprice in pairs(descendants) do
				if drealprice.Name == "RealPrice" then
					drealprice.Value = dprice.Value * pricemultiplier.Value
				end
			end
		end
	end
1 Like

Just to reaffirm this, the values stored within instances suffixed by the word “Value”, such as IntValue, StringValue, ObjectValue etc. have their values stored in their “Value” property, so you need to index this property in order to retrieve the stored value.