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
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.
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
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.