-
What do you want to achieve? Condense the amount of player added events to stop lag
-
What is the issue? Server lags when people join.
-
What solutions have you tried so far? Tried doing script profiler, player added events are very high.
Then profile whatever code is running because of the PlayerAdded events. You need to narrow it down.
What code actually has the player added events?
its not good… theres like 69 things that hvae player added in them
What scripts are using the event?
That shouldn’t be too bad in the event system, but it’s not a good practice. Have you considered using modules that you can run methods on whenever there’s a player that joined?
Would that make it so there’s only one player added event but I can have multiple scripts detecting it? Or would I have to do something else?
You can just have a callback function that you can make.
Can you explain how I’d do that
That is a lot of PlayerAdded
Events, I’d recommend switching to a modular code base instead to resolve this issue. Usually I’d use about 1 - 5 PlayerAdded
Max, and do something like this:
local Module = require("path.to.module")
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player: Player)
Module.PlayerAdded(player)
...
end)
It is really just personal preference but you need to tone down the PlayerAdded
Events, Reduce the amount of scripts you have in your code base and use ModuleScripts
more often.
How can I use my code in a module script and condense it all down? I have player.chatted events too for playeradded
local Module = require("path.to.module")
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player: Player)
Module.PlayerAdded(player)
player.Chatted:Connect(function(message)
Module.PlayerChatted(player, message)
end)
...
end)
Something similar to this.