I am trying to code various player stat bars, and I made a function to calculate the percentage of stat health to max stat health, and then to apply it to the GUI bar size.
'playerstats' is a folder within Player that holds several stat IntValues. Here is my function:
function statChange(player, stat)
for x in player.playerstats do
if x.Name == stat then
percent = x/maxstathealth -- percent is defined above as 'local percent', and 'local maxstathealth = 100'
end
end
for x in screengui do -- I have various frames within screengui that are named after the stats
if x.Name == stat then
x.Size = UDim2.new(percent, 0, 1, 0)
end
end
end
I get the error "Trying to call method on object of type: Folder with incorrect arguments." on the second line:
for x in player.playerstats do
I'm not entirely sure what this means, or how to fix it. Thank you very much in advance!

5 comments
I don't think you can do that, start a for loop like you do
Hmm, why not? Is there an alternative?
What do you think that x is? I mean on line 3, you do x.Name, and on line 4 you do x/maxstathealth
Do you want to loop through the children of the Folder?
Yeah, that's what I want to do. Wait, I just realized there is something called GetChildren()/. Is that what I am supposed to use?