Repeatedly getting attempt to index local 'victimHumanoid' (a nil value) on something that already exists

I am working on my damage system for my fighting AI using Region3 and etc. However when I try to get the Humanoid of the Player it keeps saying it’s a nil value. I tried almost anything that I know of and gave up, I could really use some assistance for this.

Code:

local HitBox = function(BodyPart, damage, size, typ, bool)
	local hitted = false
	if not hitted then
		local region = NewRegion(BodyPart.CFrame, size)
		
		for _,v in pairs (CastRegion(char, math.huge, region)) do
			if v.Name == "Wall" then return end
				if v.Parent:FindFirstChild("HumanoidRootPart") then
				local hum = v.Parent:FindFirstChild("Humanoid")
				if not hitted and hum then
					hitted = true 
					Damage(typ, damage, hum)
				end
			end
		end
	end
	if not bool then
		hitted = true
	end
end

Error:
Workspace.Dio.Handler:298: attempt to index local ‘victimHumanoid’ (a nil value)

1 Like

I can’t see any variable named ‘victimHumanoid’ inside this script, are you sure you have the correct script.

1 Like

Are you sure that error was from this script?
I don’t see a local victim humanoid.
Give us the script ‘Dio handler’

1 Like

Yes, I passed along hum as a argument with hum basically = victimHumanoid

Yes, I passed along hum as a argument with hum basically = victimHumanoid, I am afraid to say that I can’t show you the entire script.

I am confused because how it finds the HumanoidRootPart then? if it finds HumanoidRootPart it should find Humanoid as well?

Nevermind, sorry guys I did something stupid when I doing the Damage Function and added a extra argument of the local player thinking it was remotes.