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
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!