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

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

Asked by 5 years ago

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?

0
All functions in lua are anonymous. They don't have names User#19524 175 — 5y
0
No. That's merely its variable that references it. User#19524 175 — 5y
0
Okay, my apologies. Well is it possible a referenced function PoePoeCannon 519 — 5y
View all comments (2 more)
0
Okay, I figured out what i can do. When this event is fired, I just run a different function inside of that one. PoePoeCannon 519 — 5y
0
ok User#19524 175 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

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)
Ad

Answer this question