Carrying system glitching out when 2 knocked characters are near eachother

I made this carrying system a few days ago that im currently really proud of, today i found this game breaking bug that could mess up some players and purposely glitch out people so they are forced to rejoin, making them lose all data because of my combat tagging system:

Explanation

The glitch happens when 2 knocked characters are near eachother, one of them will be carried then instantly dropped, putting them in this limbo kind of state where they cant be picked up and arent able to stand up
image

Possible problems

im currently using magnitude to identify if a character is knocked, im not giving out my full script as i think magnitude is the problem behind this bug:

local distance = (CHARACTER.HumanoidRootPart.Position - v.HumanoidRootPart.Position).magnitude

if distance <= range and v.Character.Values.Downed.Value == true and v.Character.Values.BeingCarried.Value == false and CARRYING == false then

CARRYING = true

Authorized = false

v.Character.Values.Ragdolled.Value = false

v.Character.Values.BeingCarried.Value = true

Id love to see someone explain to me why this bug occurs and give me a possible fix so this doesnt cause anymore problems later in development.

1 Like

Since you are looping through the workspace and seeing how close they are to you (I’m assuming that’s what you are doing.) why don’t you just return it when it finds one player so it can’t pick up 2 or more players?

1 Like

i would but, i wanna make it so you can pick up one of the two characters, for the sake of not allowing them to stand up.

Yeah, returning would allow you to pick up one of the players instead of picking them both up. Put return at the end of the code where the script does all the other things.

I see, as im not very experienced could you teach me how to detect if there is more than 2 players/characters?

for i, v in pairs(game.Workspace:GetChildren()) do
    local distance = (CHARACTER.HumanoidRootPart.Position -v.HumanoidRootPart.Position).magnitude
    if distance <= range and v.Character.Values.Downed.Value == true and v.Character.Values.BeingCarried.Value == false and CARRYING == false then
               --The carrying code RIGHT here before the return. It will get only player within the distance.
        return
    end
end
1 Like

It works, but it no longer lets me uncarry people and will instantly carry them again

i finally got it working, thanks for the help