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.
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)
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?
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
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?