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

Cannot get my humanoid to move at all?

Hi, I've been at this for hours. I teach kids game development, and they've recently been asking to do a Roblox mod. I don't know how to do this, but I figured I can make a lesson plan over the next few months so we can do it next year. I'm trying to get an NPC to move, but I'm having trouble.

Here is my code currently:

function Enemy:OnCreate()

while (true) do

	wait(2)
	local target = self:GetNearestPlayer()
	if (target) then

		local torso = target:GetTorso()
		self.object.NPC.Humanoid:MoveTo(torso.Position, torso)

	end

end

end

I am using CodeKingdoms because it is easier for my students to understand. If someone could help me out that would be awesome. Thanks!

5 comments

1

what you teach students code that isn't yours? i'm confused

0

How and when is the function executed?

0

Is it anchored?

0

It is my code. CodeKingdoms just makes it node based. Easier for kids to grasp.

0

It is not anchored. And it is in OnCreate

1 answer

Hello, austeefrostee!

If you want the NPC to teleport somewhere, then you're doing almost correctly... Just a little change needed

function Enemy:OnCreate()

while (true) do

    wait(2)
    local target = self:GetNearestPlayer()
    if (target) then

        local torso = target:GetTorso()
        self.object.NPC:MoveTo(torso.Position) -- ":MoveTo" is not a Function of the Humanoid, but of the Model

    end

end

end

But, if you want the NPC to WALK to the player, then you should do this:

function Enemy:OnCreate()

while (true) do

    wait(2)
    local target = self:GetNearestPlayer()
    if (target) then

        local torso = target:GetTorso()
        self.object.NPC.Humanoid:WalkToPoint(torso.Position) -- ":WalkToPoint" makes the humanoid walk to a position(in this case, player's torso)

    end

end

end

Useful links:

https://developer.roblox.com/api-reference/property/Humanoid/WalkToPoint

https://developer.roblox.com/api-reference/property/Humanoid/WalkToPart

https://developer.roblox.com/api-reference/function/Model/MoveTo

PS: I'm using normal roblox codes(for roblox studio, game creation), I don't know if this will work for a mod

7 comments

1

Humanoid:MoveTo is valid and :WalkTo isn't a thing

0

WalkTo could be a thing with the CodeKingdoms thing, not sure

0

CodeKingdoms just turns everything node based. It's the same code. WalkTo is sadly not a thing I can do.

0

How would you normally make an npc walk towards something else?

0

@austeefrostee the second example, use :WalkToPoint() -- I'm editing the script to solve a error, sorry for that

0

@incapaz ok, but I preffer using :MoveTo() on the model because it is a funcion of it

0

@leamir So MoveTo should be making the character walk? It still isn't happening sadly.

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