I’m trying to work on my own framework that uses modules only for future games and I need help with a few things.
here is my current framework
Replicated Storage:
Server Storage:
and then I have single script for each one to require all modules.
I have some questions.
-
- Do you have any similar framework, anything you do different?
-
- How should I do playerAdded, player.CharacterAdded Events?
Should I make 1 event in the script that requires all modules, and then use a for loop to loop through the modules and call the playerAdded function?
- How should I do playerAdded, player.CharacterAdded Events?
as you see here this is inside the script, so theres only 1 playerAdded/CharacterAdded event throughout the whole server side
local function playerJoined(player)
for module, class in modules do
pcall(function()
class:PlayerJoined(player)
end)
end
player.CharacterAdded:Connect(function(character)
for module, class in modules do
pcall(function()
class:CharacterJoined(character)
end)
end
end)
end
for _, player in players:GetPlayers() do
playerJoined(player)
end
players.PlayerAdded:Connect(playerJoined)
and then inside the module is this
function exampleService:PlayerJoined(player: Player)
warn('Player Joined')
end
function exampleService:CharacterJoined(character: Model)
warn('Character Joined')
end
The problem about this is there not running on seperate threads, so while loops in the characterjoined will yeild the other modules from running.
or can I and is it safe to make multiple events like this?
-- // Module 1
function exampleService:Init()
game:GetService('Players').PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
end)
end)
end
-- // Module 2
function exampleService:Init()
game:GetService('Players').PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
end)
end)
end
-- // Module 3
function exampleService:Init()
game:GetService('Players').PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
end)
end)
end
-
- How should I do while loops? doing something like this causes a yield and stops other modules from running
function exampleService:Start()
while true do
end
end
so should I do something like this, creating a thread and putting the while loop inside?
function exampleService:Start()
coroutine.resume(coroutine.create(function()
while true do
end
end))
end
I thinks thats everything that I need help with, let me know how you’ll go about doing these things.