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

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

Asked by 6 years ago
Edited 6 years ago

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
0
Post some code otherwise it's too vague. MooMooThalahlah 421 — 6y
0
:GetChildren() User#20388 0 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

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!

Ad

Answer this question