How do I make my zombie take the damage set from the gun?

https://streamable.com/b5y1wg

I got help from the DevForum on how to make the zombie, but there is a problem with it. the local DMG = 10 will always make it take 10 damage from my gun. because it is set that way, but I want the local DMG to equal the bullet damage, how would I do that?

Gun Code
MainScript
local RP = game:GetService("ReplicatedStorage")
local remoteFunction = RP:WaitForChild("RemoteFunction")
local Bullet = RP:WaitForChild("Bullet")

local tool = script.Parent

local bulletSpeed = 200
local bulletDMG = 10
local Firerate = 0.3


local Shooting = false
tool.Activated:Connect(function()
	if Shooting == false then
		Shooting = true
		
		
		local player = game.Players:GetPlayerFromCharacter(tool.Parent)
		local MouseHitLookVector = remoteFunction:InvokeClient(player)
		
		local bulletCreation = Bullet:Clone()
		bulletCreation.CFrame = tool.Handle.CFrame
		bulletCreation.Parent = game.Workspace
		
		bulletCreation.Velocity = MouseHitLookVector*bulletSpeed
		
		
		
		
		wait(Firerate)
		Shooting = false
	end


end)
TriggerFire
local RS = game:GetService("ReplicatedStorage")

local RemoteFunction = RS:WaitForChild("RemoteFunction")

local player = game.Players.LocalPlayer

local mouse = player:GetMouse()

RemoteFunction.OnClientInvoke = function()

return mouse.Hit.LookVector

end
Zombie Scripts
MainScript
local Zombie = script.Parent
local zombieHuman = Zombie:FindFirstChild("Zombie")
local root = Zombie:WaitForChild("UpperTorso")

local hitbox = Zombie:WaitForChild("HitBox")

local DMG = 10 --I do not know how to make this the bulletDMG from the gun script.

hitbox.Touched:Connect(function(hit)
	local human = hit.Parent:FindFirstChild("Humanoid")
	if human and hit.Parent.Name ~= "Zombie" then
		human.Health -= 5
	end

	if hit.Name == "Bullet" then
		zombieHuman.Health -= DMG
		print("Bullet hit")
		hit:Destroy()
		if zombieHuman.Health > 0 then return end
		_G.deadZombies += 1
		Zombie:Destroy()
	end
end)



function nearPersonPos()
	local closest
	local bestDist = 1000 
	for _,v in pairs(game.Players:GetPlayers()) do
		local char = v.Character
		local tors = char and char:FindFirstChild("UpperTorso")
		if not tors then continue end
		local dist = (tors.Position-root.Position).Magnitude
		if dist >= bestDist then continue end
		closest = tors.Position
		bestDist = dist
	end
	return closest
end

while zombieHuman.Health > 0 do
	zombieHuman:MoveTo(nearPersonPos() or root.Position) 
	wait(1)
end
1 Like

Is the “Zombie” instance inside the Zombie the humanoid? The ‘zombieHuman’ variable tries to find something called “Zombie” and not “Humanoid”.