Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

0

I don't think you can do that, start a for loop like you do

0

Hmm, why not? Is there an alternative?

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

0

Do you want to loop through the children of the Folder?

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?

1 answer

✓ Accepted answer

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

4 comments

0

Thank you for the response! How do I mark this as solved?

0

Yeah and if you do this you have to change on line4 to x.Value

0

Yep, I realized that haha

0

just hover ur cursor over my answer to accept my answer

This discussion is preserved as it was. New answers, comments, and votes are closed.