Why is fighter nil?

--LOCAL SCRIPT
local fighters = sentPets:GetChildren()	
	AttackEvent:FireServer(fighters,mob)
-----------------------------------------------------
--SERVER SCRIPT
replicatedStorage.Remotes.AttackEvent.OnServerEvent:Connect(function(player,fighters,mob)
	AttackModule.Attack(fighters,mob)
-----------------------------------------------------
--MODULE SCRIPT
local AttackModule = {}

local replicatedStorage = game:GetService("ReplicatedStorage")
local Remotes = replicatedStorage:WaitForChild("Remotes")

local animateFighter = Remotes:WaitForChild("AnimateFighter")

function AttackModule.Attack(fighter,mob,player)
		local config = fighter.Config
		local target = mob

			local targetCFrame = CFrame.lookAt(fighter.HumanoidRootPart.Position, target.HumanoidRootPart.Position)
			fighter.HumanoidRootPart.BodyGyro.CFrame = targetCFrame

			animateFighter:FireAllClients(fighter,"Punch",target)

			target.Humanoid:TakeDamage(config.Damage.Value)

			if target.Humanoid.Health <= 0 then
				print("Killed")
			
			end

			task.wait(config.Cooldown.Value)

		if fighter and fighter.Parent then
			AttackModule.Attack(fighter,player)
	end
end

return AttackModule

end)

im trying to send everything in a folder as a variable but it just comes back nil. am i doing something wrong? i dont know what to do

Is this the folder you are trying to send? Just making sure.
image

yes ---------------------------------------- character limit

image
“figher” is an array, this will not work.

Perhaps you meant fighter[1].HumanoidRootPart

1 Like

ohhhh, ok so to do this for all of them i could use a for loop?

1 Like

Mhm, you definitely could. ,

No I don’t think this is the issue, using fighter[1] only looks at the first index of an array, this doesn’t mean that the first item is the Character specifically (unless you specifically put the character as the first item of an array).

If you want to look for a character in an array then you need to loop through the entire array and compare the value with your character until they match, then define the HumanoidRootPart

And the only other reason why something might return nil after passing it as an argument is because the argument you are trying to pass might not exist on the server (or not exist in the same way). If the sentPets exist only on the client, or exist on the client first then the server will not know about its existence, therefore returning nil.

If the client is sending an array of parts that the server does recognize then it should pass without an issue, you can pass an array as an argument just fine.

2 Likes

well what he said did work but i will keep in mind what you said for future events

1 Like