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

Why does the Studio crash when I set up a 'for' loop like this? [Semi-Answered]

Today, I was testing and creating a new code for an upcoming project, but, the whole studio crashed when I tested a specific for loop within the Commands Bar. I do not know why it crashes like this, but it crashes every time I run it. This is the code;

local Table = {
	"Player1",
	"Player2",
	"Player3"
}

for i, v in pairs, Table do
	print(i, v)
end

There's not much more I can explain sadly, only that it crashes when I use it. :(

-EDIT-

The purpose of why I coded the for loop like this was because I was curious on something; "I've seen 'for v in next, Table do', and 'for i, v in pairs (Table) do', so what happens if I set them up oppositely?" After setting up the code like this, it crashed when I ran it, thus my Question.

-EDIT2-

I just tested this code;

local Table = {
    "Player1",
    "Player2",
    "Player3"
}

for i, v in next (Table) do
    print(i, v)
end

But it only resulted in an error. Very interesting..

-EDIT3-

I took Smrt's Answer into account and used a wait function, and it returned function: 0EDC2EB8 table: 0EFAD730, repeatedly spamming it into the Output box. Why is this?

2 comments

0

try doing in pairs (table) instead

0

@TheDeadlyPanther That's what I usually use. :P But my Question is 'why does this type of for loop crash the studio?'

1 answer

I recommend you to add "wait ()"

2 comments

0

Never crossed my mind to do that. XD Ok, I'll try and see what happens. :)

0

Huh, that prevented crashing, but something came up in the Output: 'function: 0EDC2EB8 table: 0EFAD730'. This has been spamming since I fired the code. Do you know why it's sending this back?

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