why cant i destroy the messages inside the MessageFolder in this piece of code
local Message = game.workspace.MessageFolder:GetChildren()
Message:Destroy
why cant i destroy the messages inside the MessageFolder in this piece of code
local Message = game.workspace.MessageFolder:GetChildren()
Message:Destroy
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)
This discussion is preserved as it was. New answers, comments, and votes are closed.