Keeping them all in different services is fine.
The only reason why you’d want to combine them all together is if you need certain things to be loaded first (Like a saving system).
My solution (probably not the best one) is to have one service manage all PlayerAdded events to make sure that the ones I want loaded first do actually load first.
Here’s the script if you want to look at it for some reason. (this is sort of old so I suggest remaking it yourself)
local Knit = require(game:GetService("ReplicatedStorage").Knit)
local Players = game:GetService("Players")
local Thread
local PlayerService = Knit.CreateService({
["Name"] = "PlayerService";
["Client"] = {},
["__maxPriority"] = 1,
["NumberOfPlayers"] = 0,
["__playerAddedCallbacks"] = {},
["__playerRemovedCallBacks"] = {},
})
local function firstAdded(player)
PlayerService.NumberOfPlayers = #Players:GetPlayers()
end
local function firstRemoved(player)
PlayerService.NumberOfPlayers = #Players:GetPlayers()
end
function PlayerService:__callCallbacks(callbacks,...)
local args = {...}
for index = 1,self.__maxPriority do
local callback = callbacks[index]
if callback then
print(callback)
print("[PlayerService]: Calling... ",index)
callback(unpack(args))
end
end
end
function PlayerService:AddCallbackFor(eventName,priority,func)
local callbacks = (eventName == "playerRemoved" and self.__playerRemovedCallBacks) or self.__playerAddedCallbacks
priority = priority or (#callbacks + 1)
self.__maxPriority = self.__maxPriority < priority and priority or self.__maxPriority
callbacks[priority] = func
-- print(string.format("[PlayerService]: Callback added to event: %s with priority of %d",eventName,priority))
-- print(callbacks)
end
function PlayerService:KnitStart()
Thread = require(Knit.Shared.Lib.Thread)
self:AddCallbackFor("playerRemoved",1,firstRemoved)
self:AddCallbackFor("playerAdded",1,firstAdded)
warn(self.__maxPriority)
for _,player in pairs(game.Players:GetPlayers()) do
self:__callCallbacks(self.__playerAddedCallbacks,player)
end
game.Players.PlayerAdded:Connect(function(player)
self:__callCallbacks(self.__playerAddedCallbacks,player)
end)
game.Players.PlayerRemoving:Connect(function(player)
self:__callCallbacks(self.__playerRemovedCallBacks,player)
end)
end
function PlayerService:KnitInit()
end
return PlayerService