So I have some functions that I added into a table like this:
table.insert(connections, T2Player2.CharacterRemoving:Connect(function(hit)
T2Player2Dead = true
checkDeaths()
end))
These work perfectly fine but when I try to do this it doesn’t work:
table.insert(connections, checkDeaths())
table.insert(connections, checkPlayerLeft())
It’s probably because you’re calling the function while adding it to the table, try removing the parentheses to see if that works
3 Likes
I tried that but now I’m getting an error message when I try to disconnect them
ServerScriptService.ArenaScript:208: attempt to index function with 'Disconnect'
No. That is not how Lua works. It insteads calls the function and THEN inserts it to the table.
If you meant however adding functions to the table, this is how you would do it.
Then I think I’m misunderstanding something here because the title is “How to add functions into a table?” Is there something I’m missing or what?
12345koip
(12345koip)
#6
Adding parentheses will add the return value of a function to the table. You’re looking to add a connection. You can store a connection in a variable.
local connection:RBXScriptConnection = workspace.Part.Touched:Connect(functionHere)
--then do:
table.insert(connections, connection)