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

Can you connect a non-anonymous function to ChildRemoved event?

Basically, I want to connect a function to child removed event like so

local folder = workspace.Folder

local function onRemove(itemRemoved)
	-- how can i get the folder that the item was removed from?
end

folder.ChildRemoved:Connect(onRemove)

I want to write a function once and connect it to many different folders; however, I don't know how to access the folder because i cant do

local function onRemove(itemRemoved)
	itemRemoved.Parent
end

because the itemRemoved has had its parent changed.

Does anyone know a way to get the parent it was removed from without doing an anonymous function?

6 comments

0

All functions in lua are anonymous. They don't have names

0

No. That's merely its variable that references it.

0

Okay, my apologies. Well is it possible a referenced function

0

Okay, I figured out what i can do. When this event is fired, I just run a different function inside of that one.

0

ok

1 answer

If anyone comes across this situation in the future, one thing I did to fix this is create a function and run it inside of the connected event function like so

local folder = workspace.Folder

local function onRemove(itemRemoved)
    
end

folder.ChildRemoved:Connect(function(itemRemoved)
	onRemove(itemRemoved) -- call the function here and pass the value
end)

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