So, I've added a feature in my game that turns the player into a ragdoll when they die. Beforehand, I had a script that prevented players from colliding with each other, and themselves. Since players cannot collide with themselves, the ragdoll looked a bit odd. I wanted to get it so that the players could collide with themselves, but not others. So, I decided to modify the script that deals with player collisions so that players can collide with themselves, and not others.
Here's the script:
local ps = game:GetService("PhysicsService")
game.Players.PlayerAdded:Connect(function(plr)
local name = plr.Name
ps:CreateCollisionGroup(name)
ps:CollisionGroupSetCollidable(name, name, true)
for i, v in pairs(ps:GetCollisionGroups()) do
if (game.Players:FindFirstChild(v[3])) then
ps:CollisionGroupSetCollidable(v[3], name, false)
end
end
plr.CharacterAdded:Connect(function(chr)
for i, v in pairs(chr:GetDescendants()) do
if (v:IsA("BasePart")) then
ps:SetPartCollisionGroup(v, plr.Name)
end
end
end)
end)
Whenever a player joins, create their own collision group, iterate through all the others, disable collisions with other players, and every time the player respawns, set the collision group of all of their character's BaseParts to the player's designated collision group.
But, there's an issue. I'm getting an error on line 9 and presumably on line 10. The error is saying that the variable v is a table, but does not have any elements, when it should. I know that it should have elements, because of this page.
The function GetCollisionGroups should return an array containing arrays, where an array is created for each collision group that is in the game, and each array contains three elements: an integer which is the ID of the group, another integer which is the mask of the group, and a string which is the name of the group.
What I'm getting is an array, with an array for each collision group, but those arrays that represent collision groups do not contain any elements.
But shouldn't they? I printed the length of the array that is returned by the function, and it printed "2", because of the default collision group and the collision group that was created for the player right before the function was called. So that means it's getting the number of collision groups right.
I printed the datatype of the two elements of the array that was returned and it said "table."
So it's getting the number of collision groups right, and it's creating an array for each collision group, but when I attempt to access elements of the arrays that represent those collision groups, I get an error, because the arrays do not contain elements, when they should.
I am clueless. I do not know what is occurring. Any help would be greatly appreciated.
