Extremely Laggy Game

I just spent 20k robux on ads for my game, and sadly there is a huge lag problem when there is a lot of players in my game.

I have only had this issue when there are a lot of players. And the average ping is horrible, reaching up to 1000 sometimes.

I really need help fast figuring out what is causing this lag. I am wondering if it is this script that disables player collisions, since it says the rate is 30k+ times per second, and that would make sense to cause lag with more players.


I do not know if that is correct though, because it would have a lot of activity, and be running constantly if this were the case.

I don’t know if joining the game will help, but here is the link:

Thanks for all your help!

3 Likes

I just thought of something. I recently changed all of my wait() to task.wait()

Would this for some reason have an effect?

1 Like

That should not make that much of a performance difference. I think the issue is how the scripts were coded

1 Like

spread script?
image

the thing that dupe themself to lag the game?

2 Likes

perhaps you have too many scripts using wait(); every frame.
Try changing some to wait(.1) or wait(1) if they can run a lot less…

2 Likes

No, pretty sure there is no virus.

2 Likes

I never had this issue before when I ran ads. Maybe all the meshes my dev added recently? I don’t know, this is not good, and I am losing players.

2 Likes

Could you please show the script that is causing 30k+ rates? Maybe the problem is there

1 Like

So you’re saying the script disables the player collisions in the rate of 30K+/sec?

1 Like

Update, now its saying 36k.


Here is the script:

local Players = game:GetService("Players")
 
local playerCollisionGroupName = "Players"
PhysicsService:CreateCollisionGroup(playerCollisionGroupName)
PhysicsService:CollisionGroupSetCollidable(playerCollisionGroupName, playerCollisionGroupName, false)
 
local previousCollisionGroups = {}
 
local function setCollisionGroup(object)
  if object:IsA("BasePart") then
    previousCollisionGroups[object] = object.CollisionGroupId
    PhysicsService:SetPartCollisionGroup(object, playerCollisionGroupName)
  end
end
 
local function setCollisionGroupRecursive(object)
  setCollisionGroup(object)
 
  for _, child in ipairs(object:GetChildren()) do
    setCollisionGroupRecursive(child)
  end
end
 
local function resetCollisionGroup(object)
  local previousCollisionGroupId = previousCollisionGroups[object]
  if not previousCollisionGroupId then return end 
 
  local previousCollisionGroupName = PhysicsService:GetCollisionGroupName(previousCollisionGroupId)
  if not previousCollisionGroupName then return end
 
  PhysicsService:SetPartCollisionGroup(object, previousCollisionGroupName)
  previousCollisionGroups[object] = nil
end
 
local function onCharacterAdded(character)
  setCollisionGroupRecursive(character)
 
  character.DescendantAdded:Connect(setCollisionGroup)
  character.DescendantRemoving:Connect(resetCollisionGroup)
end
 
local function onPlayerAdded(player)
  player.CharacterAdded:Connect(onCharacterAdded)
end
 
Players.PlayerAdded:Connect(onPlayerAdded)

It shouldn’t be, but that is what the console is saying.

I can already tell that the script is bad

If you toggle the collisions too often, of course it will lag because Roblox’s internal will have to do caluclations in order to provide the best collision for each individual player’s character model. Why are you planning to toggle their collisions too often anyways?

1 Like

Here are the things taking up the most memory:




Like stated, I am not. This is what the console is saying. It is only supposed to toggle every time a player respawns.

1 Like

The script is the same as this roblox developer hub post: Detecting Collisions | Roblox Creator Documentation

2 Likes

Then there is definitely somthing wrong in your code. Either it is the code’s issue or you’re letting the players die too often.

2 Likes

You should tell your scripter to change the script. The script is changing collision everytime the player respawns and also is changing the collision when every part of the character is added or removed. I can see why this would cause huge lags

1 Like

If I understand correctly. The script should disable collision between players every time player respawns?

I am the scripter. I was assuming that it was okay as it was an official developer hub post. (see here)

The players do get reset pretty often in this game, but isn’t this the only way how to make the player character non-collide able with other characters? If there is a better way, what is it?

2 Likes