Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Cannot get my humanoid to move at all?

Asked by 5 years ago
Edited 5 years ago

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!

1
what you teach students code that isn't yours? i'm confused User#19524 175 — 5y
0
How and when is the function executed? MageMasterHD 261 — 5y
0
Is it anchored? Darkcraft10 20 — 5y
0
It is my code. CodeKingdoms just makes it node based. Easier for kids to grasp. austeefrostee 5 — 5y
0
It is not anchored. And it is in OnCreate austeefrostee 5 — 5y

1 answer

Log in to vote
2
Answered by
Leamir 3138 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

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

1
Humanoid:MoveTo is valid and :WalkTo isn't a thing User#19524 175 — 5y
0
WalkTo could be a thing with the CodeKingdoms thing, not sure User#22604 1 — 5y
0
CodeKingdoms just turns everything node based. It's the same code. WalkTo is sadly not a thing I can do. austeefrostee 5 — 5y
0
How would you normally make an npc walk towards something else? austeefrostee 5 — 5y
View all comments (3 more)
0
@austeefrostee the second example, use :WalkToPoint() -- I'm editing the script to solve a error, sorry for that Leamir 3138 — 5y
0
@incapaz ok, but I preffer using :MoveTo() on the model because it is a funcion of it Leamir 3138 — 5y
0
@leamir So MoveTo should be making the character walk? It still isn't happening sadly. austeefrostee 5 — 5y
Ad

Answer this question