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

Why cant i destroy the messages inside the folder?

Asked by 10 years ago

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

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

1 answer

Log in to vote
4
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 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:Destroy()

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]
    child:Destroy()
end
-- with a generic for loop
for i, child in pairs(Message) do
    child:Destroy()
end

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

Ad

Answer this question