Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Zombies are standing on my dead body.why?

So im taking a zombie survival game and when i die then zombies just stack on my dead parts position. (And dont tell me about path finding and all that stuff cus i know that i can use that)

Heres the zombie script:

script.Parent.Touched:Connect(function(hit)
	if game.Players:GetPlayerFromCharacter(hit.Parent) then
		if script.Parent.Parent.Humanoid.Health ~= 0 then
			hit.Parent.Humanoid.Health = 0
			wait(0.3)
			local plr = game.Players:FindFirstChildOfClass("Player")
			local Hum = game.Workspace:WaitForChild(plr.Name).HumanoidRootPart
			
			while wait() do
				script.Parent.Parent.Humanoid:MoveTo(Hum.Position)
			end
		end
	end
end)

1 comment

0

check if hum's health is not zero in while loop and break it if it is.

1 answer

It's because your character hasn't been removed, therefore they will keep following you as long as your character exists. There are two ways to counter this:

  1. Check if the Humanoid inside of the Character is Dead using GetState(), or verify that the Humanoid's Health is at 0.
  2. Remove the character when its Humanoid dies. Be aware that you'll need a check in the zombies' script(s) in order to prevent them from throwing errors.

1 comment

0

Thanks bud

This discussion is preserved as it was. New answers, comments, and votes are closed.