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

Why cant i destroy the messages inside the folder?

Asked by 9 years ago

why cant i destroy the messages inside the MessageFolder in this piece of code

local Message = game.workspace.MessageFolder:GetChildren()

1 answer

Log in to vote
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

First: syntax. Message:Destroy is not valid Lua (the output will complain about this line -- always run your scripts and then always read the output). You need parenthesis to call methods:


Message will be a list -- :GetChildren() returns a list of things.

You cannot destroy a list. (What would it mean to destroy a list?)

You probably mean to destroy all the elements of the list.

Both of these snippets do that:

-- with a standard for loop
for i = 1, #Message do
    local child = Message[i]
-- with a generic for loop
for i, child in pairs(Message) do

ipairs would also work instead of pairs in the above (since Message is a list, they behave (ignoring traversal order) the same)


Answer this question