Hello! I want to disable player collisions as soon as they join the game. For now I have this script in my game but the issue is that it takes a few seconds until the collisions are disabled:
local ps = game:GetService("PhysicsService")
local players = ps:CreateCollisionGroup("Players")
ps:CollisionGroupSetCollidable("Players","Players",false)
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
repeat wait(1)until char:WaitForChild("Humanoid")
for _, characterPart in pairs(char:GetChildren()) do
if characterPart:IsA("BasePart") then
ps:SetPartCollisionGroup(characterPart, "Players")
end
end
end)
end)
I have 9 spawn locations in my map and the spawn area is quite small:
When 2 players join the game at the same time and they both are spawned at the same spawn location, one of them is going to spawn on the roof. How do I avoid this? Or how do I make it so the player can’t collide as soon as they spawned?
Your script is unnecessarily waiting until the Humanoid is loaded, even though by the time the CharacterAdded event is fired, the humanoid would have already loaded.
Your script should look like
local ps = game:GetService("PhysicsService")
local players = ps:CreateCollisionGroup("Players")
ps:CollisionGroupSetCollidable("Players","Players",false)
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
for _, characterPart in pairs(char:GetChildren()) do
if characterPart:IsA("BasePart") then
ps:SetPartCollisionGroup(characterPart, "Players")
end
end
end)
end)