Jeep (on collision with zombie) killing (using its own HP) an enemy (zombie)

Hello,

I am trying to make an Jeep, to drive though its path, and kill zombies on collision with them using its own HP. In my case, I get error that Humanoid doesn’t exist. How I can do this: JeepHP = JeepHP - ZombieHP and make zombie also get damage by JeepHP. How I can achieve this?

My script that does that part:

function findPossibleTarget()
	for _, v in pairs(Enemy:GetChildren()) do
		if v:FindFirstChild("Torso") then
			if Model.PrimaryPart then
				if (Model.PrimaryPart.Position - v.Torso.Position).magnitude < _Range.Value then
					if v:FindFirstChild("Humanoid") then
						if v.Humanoid then
							v.Humanoid.Health = (Humanoid.Health - v.Humanoid.Health)
							if Humanoid then
								Humanoid.Health = Humanoid.Health - v.Humanoid.Health
							end
						end
					end
    			end
			end
		end
	end
end

Error I get:

19:21:44.650 - Humanoid is not a valid member of Model
19:21:44.650 - Stack Begin
19:21:44.651 - Script 'Workspace.Jeep.CoreScript', Line 60 - global findPossibleTarget
19:21:44.651 - Script 'Workspace.Jeep.CoreScript', Line 73 - global onUpdate
19:21:44.651 - Script 'Workspace.Jeep.CoreScript', Line 46
19:21:44.651 - Stack End

This is what I have rightnow

This is what I am trying to achieve

If you have any questions, feel free to do so

What is line 60???

function findPossibleTarget()

I think, that you wrongly define humanoid send pls line 46-60

that line has nothing to do with that, its line that is calling that function

Oh ok, and where do you define humanoid

everything is defined properly

this also can be the problem, you have reversed math. You need to do zombie health-jeep health

You can’t do if v.Humanoid then. It will give an error. Replace it with if v:FindFirstChild(“Humanoid”) then and you should be good to go. EDIT: Didn’t see line above so I’m not sure if what I said will fix it or not. In future doing checking something like that won’t work if it doesn’t exist.

1 Like

I was working a bit, this doesn’t give error but doesn’t work

function findPossibleTarget()
	for _, v in pairs(Enemy:GetChildren()) do
		if v:FindFirstChild("Torso") then
			if Model.PrimaryPart then
				if (Model.PrimaryPart.Position - v.Torso.Position).magnitude < _Range.Value then
					if v:FindFirstChild("Humanoid") then
						if v["Humanoid"] and Humanoid then
							local ZombieHP = v.Humanoid.Health
							local TowerHP = Humanoid.Health
							v["Humanoid"]:TakeDamage((ZombieHP - TowerHP))
							Humanoid:TakeDamage((TowerHP - ZombieHP))
						end
					end
    			end
			end
		end
	end
end

How does take demage work???

Oh, I thought its your function. So you must only enter hp of the other object. Because takedamage will decrease the hp itself.

then how you lower your own HP? You dont have infinite health right?

Takedemage is decreasing hp and when jeep have 1000 hp and zombie 100 you will decrease -900 hp, so you will heal him, so only decrese it by truck.
Takedemage will do inside
Hp=Hp-parametr1

1 Like

Your right, it worked, Thanks!