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

Why am I getting the stack overflow error and how can I fix it?

Im making a script for a game using magnitude, and when I :getChildren() on workspace it gives me the, "stack overflow" error. Why is this occuring? and how do I fix it?

local w = game.Workspace:children()
	for i = 1, #w do

2 comments

0

Post some code otherwise it's too vague.

0

:GetChildren()

1 answer

Hey! BlackOrange here to help.

First, it seems like your trying to Loop through a list of things. When you do this, there is a specific type of loop to use.

http://wiki.roblox.com/index.php?title=Generic_for

Now, let's start off with the variables:

local w = game.Workspace:GetChildren() -- not :children()

Alright, now let's understand the loop:

local w = game.Workspace:GetChildren() -- not :children()

for i, v in pairs(w) do -- i is for index, v is for value

end

So, if your Workspace has a bunch of Parts v would be each Part individually, if you want to loop through and only affect a specific item then use :IsA()

http://wiki.roblox.com/index.php?title=API:Class/Instance/IsA

The link above has a very good example.

So that's how to get rid of your error, your looping through the items.

Hopefully this helped. Remember! Put a wait() in your loop.

Best of luck!

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