How to minimize playeradded events to stop lag when player joined

  1. What do you want to achieve? Condense the amount of player added events to stop lag

  2. What is the issue? Server lags when people join.

  3. What solutions have you tried so far? Tried doing script profiler, player added events are very high.

2 Likes

Then profile whatever code is running because of the PlayerAdded events. You need to narrow it down.

2 Likes


Now this is the most active thing, and I have no idea what this means at all

3 Likes

What code actually has the player added events?

1 Like

its not good… theres like 69 things that hvae player added in them
image

3 Likes

What scripts are using the event?

1 Like

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.