I made a zombie recently for a game. I asked the DevForum 2 times for help and when I thought I fixed all the issues, another one appeared. This time, if you don’t kill the zombie in like 2.3 seconds, it will gain complete invincibility to the gun. I don’t understand how but it happens.
I don’t even know which thing is causing the problem, my gun or my zombie.
Gun Code
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)
Gun Code (Local Script)
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 Code
local Zombie = script.Parent
local zombieHuman = Zombie:WaitForChild("Zombie")
local root = Zombie:WaitForChild("UpperTorso")
local hitbox = Zombie:WaitForChild("HitBox")
local DMG = 10
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
After a few seconds, the bullets either go right through the zombie, or bounce off the zombie.
Video of my issue:
https://streamable.com/oua6nu