Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[SOLVED] "Trying to call method on object of type: `Folder` with incorrect arguments."?

Asked by 4 years ago
Edited 4 years ago

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!

0
I don't think you can do that, start a for loop like you do Spjureeedd 385 — 4y
0
Hmm, why not? Is there an alternative? akatak_prime 48 — 4y
0
What do you think that x is? I mean on line 3, you do x.Name, and on line 4 you do x/maxstathealth Spjureeedd 385 — 4y
0
Do you want to loop through the children of the Folder? Spjureeedd 385 — 4y
0
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? akatak_prime 48 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

you can't do that, if your trying to go through the children of player.leaderstats then you'd have to do it like this: for _, item in pairs(player.leaderstats:GetChildren()) do

0
Thank you for the response! How do I mark this as solved? akatak_prime 48 — 4y
0
Yeah and if you do this you have to change on line4 to x.Value Spjureeedd 385 — 4y
0
Yep, I realized that haha akatak_prime 48 — 4y
0
just hover ur cursor over my answer to accept my answer User#23252 26 — 4y
Ad

Answer this question