GetDescendants() Bug

I’m pretty sure this is a bug but if it isn’t then correct me, anyways can someone help me with this short code to find a way around this.
It keeps acting like it cant find the correct ratio and just returns the original value 0.
Place it in player scripts and see for yourself.

Nevermind I fixed it by converting the gear value to a string

local Stats = script.Stats
local Gear = Stats.Gear
local CurrentGear = 0
for _,Child in pairs(Stats.Gears:GetDescendants()) do
print(Child.Name)
if Child.Name == tostring(Gear.Value) then -- Here I converted the value to a string
CurrentGear = Child.Value
end
end

print(CurrentGear)

The condition of that if statement will only evaluate to true if the compared instances (operands) surrounding the “is equal to” operator (==) are references (point to) the exact same instance, if they are two separate instances which happen to share the same name then as you worked out, you’d need to compare the string values assigned to their “Name” properties instead, as even if the instances are separate from one another these values will be equal to one another.

1 Like