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

For a few hours I've been trying to get this zombie to move to a player but it won't work?

The script has changed every time I've tried everything. First I tried to get players from in pairs, then have it choose a random player and move towards the picked player humanoid root part but that wouldn't work. Now I am attempting to create a sight hitbox so if a player is within it then it will move towards the player. The issue I'm having is that it is saying "MoveTo is not a valid member of Part "Workspace.Zombie.HumanoidRootPart". " the damage one is working.

local zombie = script.Parent
local humanoid = zombie.HumanoidRootPart
local hitbox = zombie:WaitForChild("HitBox")
local damage = zombie.Configuration.damage.Value

hitbox.Touched:Connect(function(hit)
	if hit.Parent then
		local human = hit.Parent:FindFirstChild("Humanoid")
		if human and hit.Parent.Name ~= "Zombie" then 
			human.Health = human.Health - damage
		end
		if hit.Name == "Bullet" then
			humanoid.Health = humanoid.Health - hit.Parent:FindFirstChild("Damage").Value
			hit:Destroy()
			if humanoid.Health <= 0 then
				zombie:Destroy()
			end
		end
	end
end)
-- end of damage script everything above works

-- start movement



local sight = zombie.sight -- 2nd hitbox for movement
sight.Touched:Connect(function(hit)
	local charr = hit.Parent:FindFirstChild("Humanoid")
	local char = hit.Parent:FindFirstChild("HumanoidRootPart")
	if charr and hit.Parent.Name ~= ("Zombie") then
		humanoid:MoveTo(char.Position)
	end
end)

1 comment

0

Had to define the primary part of model, but it isn't making the zombie walk, just teleporting it into the player.

1 answer

Had to define the primary part of model, and incorrectly used the humanoidrootpart instead of the humanoid for movement.

local zombie = script.Parent
local zombiehuman = zombie.Humanoid
local humanoid = zombie.HumanoidRootPart
local hitbox = zombie:WaitForChild("HitBox")
local damage = zombie.Configuration.damage.Value

hitbox.Touched:Connect(function(hit)
	if hit.Parent then
		local human = hit.Parent:FindFirstChild("Humanoid")
		if human and hit.Parent.Name ~= "Zombie" then 
			human.Health = human.Health - damage
		end
		if hit.Name == "Bullet" then
			humanoid.Health = humanoid.Health - hit.Parent:FindFirstChild("Damage").Value
			hit:Destroy()
			if humanoid.Health <= 0 then
				zombie:Destroy()
			end
		end
	end
end)
-- end of damage script everything above works

-- start movement


zombie.PrimaryPart = humanoid
local sight = zombie.sight -- 2nd hitbox for movement
sight.Touched:Connect(function(hit)
	local charr = hit.Parent:FindFirstChild("Humanoid")
	local char = hit.Parent:FindFirstChild("HumanoidRootPart")
	if charr and hit.Parent.Name ~= ("Zombie") then
		zombiehuman:MoveTo(char.Position)
	end
end)

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