Help with For Loop

magna_graecia

local folders = workspace.Nations:GetChildren()
for _, folder in pairs(folders) do
	print(folder.Name)
	local team = Instance.new("Team")
	team.Name = folder.Name
	team.Parent = game.Teams
end

Where the script is:
scriptinquestion
It does not make a team for every child in the Nations folder, I don’t understand what I’m doing wrong.

What does the output show? View > Output

Maybe the script doesn’t actually run? Try putting the script in ServerScriptStorage.

3 Likes

Thanks, put it in ServerScriptService and it printed the children and made the teams. I’m guessing that it doesn’t have access from Teams?

nothing, until I put it in ServerScriptService
Capture
greece

Well, there are two types of scripts - Local scripts and Server scripts. Both of these types of scripts can run in only certain locations. For example, a server script can’t run in ReplicatedFirst because ReplicatedFirst holds local scripts. You can’t run a local script in ServerScriptService either, because ServerScriptService isn’t accessible by the client.

That’s great to hear :wink: Also consider marking my response as solved, thanks!

1 Like

thanks for the help dude, couldn’t have done it without ya :blush:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.