Player carrying system allows carrying multiple people

Good afternoon!

I’m almost finished making a carry system, and while it worked perfectly in 2-player testing, the moment I try it in 3-player testing it malfunctions, and lets the carrier pick up any amount of players, and one player is left frozen on the carrier.
Basically, when the carrier picks someone up an enemy, the string value inside the carrier turns into the enemy’s name. I also have a ‘carrying’ and 'pickedUp’ boolValue inside every character, to try and make sure the carrier doesn’t pick up more than 1 person. Here is the part in my script which picks up and drops a player.

pick up player script

game:GetService("ReplicatedStorage"):WaitForChild("AttemptPickup").OnServerEvent:Connect(function(carrier, str)
	local collectionservice = game:GetService("CollectionService")
	local carrierCharacter = carrier.Character 
	local nametag = carrierCharacter:FindFirstChild("Carrying"):FindFirstChild("enemyname")
	if str == "pickup" then
		if nametag and nametag.Value == "" then
			if carrierCharacter:FindFirstChild("Carrying").Value == false and not carrierCharacter:FindFirstChild("deb")  then
				local debounce = Instance.new("StringValue", carrierCharacter)
				debounce.Name = "deb"
				game:GetService("Debris"):AddItem(debounce,0.4)
		--player loop
	for i, player in pairs(game:GetService("Players"):GetPlayers()) do
			if player ~= carrier then
						if (carrierCharacter.HumanoidRootPart.Position - player.Character.HumanoidRootPart.Position).magnitude < 7 then
				-- check if downed and k.o
				if player.Character:FindFirstChild("Humanoid") then
					if player.Character:FindFirstChild("HumanoidRootPart") then
									if player.Character:FindFirstChild("K.O").Value == true then
										if collectionservice:HasTag(player.Character:FindFirstChild("Humanoid"), "knocked") then
                        nametag.Value = player.Name
--pick up player

drop player script

elseif str == "drop" then
		if carrierCharacter:FindFirstChild("Carrying").Value == true and nametag and nametag.Value ~= ""  then
			local enemyplayer = game.Players:FindFirstChild(nametag.Value) 
			if enemyplayer then
				if enemyplayer.Character and enemyplayer.Character:FindFirstChild("K.O").Value == true and enemyplayer.Character:FindFirstChild("Carrying").PickedUp.Value == true then
					local enemy = enemyplayer.Character
				enemy:FindFirstChild("Carrying"):FindFirstChild("PickedUp").Value = false
--dropping script
2 Likes

The problem is that you never check whether the player is already carrying someone when picking a player up.

1 Like

couldnt you just

local isCarrying = false

--code to carry
if isCarrying == false then
isCarrying = true
end
--code to drop
isCarrying = false

thats what the string in the player is supposed to do

I’m pretty sure the player loop is the problem, but I dont know how to cancel iterators

after the
if carrierCharacter:FindFirstChild(“Carrying”).Value == false and not carrierCharacter:FindFirstChild(“deb”) then

you should put
carrierCharacter:FindFirstChild(“Carrying”).Value = true

I cant do that, because it hasn’t checked the distance or k.o value of the nearest players

I meant that when someone picks someone up, you should put the carrying value as true right?

if carrierCharacter:FindFirstChild("Carrying").Value == false then
		         	if player ~= carrier then
					if (carrierCharacter.HumanoidRootPart.Position - player.Character.HumanoidRootPart.Position).magnitude < 7 then	if player.Character:FindFirstChild("Humanoid") and player.Character:FindFirstChild("HumanoidRootPart")  then
					if player.Character:FindFirstChild("K.O").Value == true then
					if collectionservice:HasTag(player.Character:FindFirstChild("Humanoid"), "Downed") then
										
											carrierCharacter:FindFirstChild("Carrying").Value = true; 	nametag.Value = player.Name

Check if the player is accurately passing the drop, maybe the player is only passing the pickup.

Tables is your method store the people who are carrying what person and check if they can be carryed