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

How can I make the Enemy Humanoid act like an NPC and follow the player?

So I just wrapped up and polished a gun script, then I went to create NPC's. These NPC's have a Humanoid named "EnemyHum". This way, player's can't kill each other.

I also want to add a feature where the glass humanoids will follow you and try to kill you with their melee weapons.

I'm not asking for any scripts, but does anyone have something that might help? Please provide some examples so I understand.

Thank you for reading! I hope I get a good answer on this post!

2 answers

There is a function in Instance Humanoid called MoveTo where the first argument is the vector3 value for the end point of where the enemy NPC will follow. Please note, you can use https://developer.roblox.com/en-us to find some descriptions for Instances, their properties, their functions and Events.

here's my follow script, you might need to make a few modifications to make it fit your specific scenario, but I hope it gives you a better idea of in which to go.

local hRP = script.Parent.HumanoidRootPart
local h = script.Parent.Humanoid	
local spawnCF = script.Parent.HumanoidRootPart.CFrame

function findPlayer()
	for _,v in next,game.Players:GetPlayers()do
		if v.Character then
			local char = v.Character
			if char:FindFirstChild("Humanoid") then
				local ptorso = char.HumanoidRootPart
				if(ptorso.Position-hRP.Position).magnitude <= 30 then
					return v
				
				end
			end
		end
	end
	return nil
end
while wait() do
	local player = findPlayer()
	if player ~= nil then
		h:MoveTo(player.Character.HumanoidRootPart.Position)
	else 
		h:MoveTo(spawnCF.Position)
	end
end

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