Greetings! While I was re-coding a bit I came to the idea of just having one PlayerAdded in the whole game inside of a Module Script which then triggers a function in every module I have added into my table. The script looks like this:
local ListeningHandler = {}
local AnimHandler = require(script.Parent:WaitForChild("AnimationsHandler"))
local SendPlayerAddedStatement = {
AnimHandler.PlayerAdded
}
local SendCharacterAddedStatement = {
AnimHandler.CharacterAdded
}
local SendPlayerRemovedStatement = {
AnimHandler.PlayerRemoved
}
game.Players.PlayerAdded:Connect(function(plr)
for _,module in SendPlayerAddedStatement do
task.spawn(function()
module(plr)
end)
end
plr.CharacterAdded:Connect(function(char)
for _,module in SendCharacterAddedStatement do
task.spawn(function()
module(char)
end)
end
end)
end)
for _,plr in game.Players:GetChildren() do
for _,module in SendPlayerAddedStatement do
task.spawn(function()
module(plr)
end)
end
plr.CharacterAdded:Connect(function(char)
for _,module in SendCharacterAddedStatement do
task.spawn(function()
module(plr)
end)
end
end)
end
------------
game.Players.PlayerRemoving:Connect(function(plr)
for _,module in SendPlayerRemovedStatement do
task.spawn(function()
module(plr)
end)
end
end)
Overall I was asking myself if this is now more efficient than having many PlayerAdded events in different scripts. Every answer is appreciated. ![]()