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

Help with getting Humanoid walk script fixed?

Asked by 7 years ago

I can't seem to get this script to work, which is inside of an R15 NPC scaled down to 0.5 and a 0.8 head to fit into my game theme. But I have a script inside of it which should make it move between a certain amount of points in a circle. There are no errors appearing in the console, but I have the script here:

local points = {game.Workspace.Points.one,game.Workspace.Points.two,game.Workspace.Points.three,game.Workspace.Points.four,game.Workspace.Points.five,game.Workspace.Points.six,
    game.Workspace.Points.seven,game.Workspace.Points.eight,
    game.Workspace.Points.nine,game.Workspace.Points.ten,
game.Workspace.Points.eleven,game.Workspace.Points.twelve} --Contains the parts that are in a model called Points in workspace

local current = 0

while true do
    wait()
    for i = 0,#points, 1 do
        current = current + 1
        script.Parent.Humanoid:MoveTo(points[current])
        repeat wait() until script.Parent.Humanoid.MoveToFinished(true)

    end
    current = 0
end

The place is Here. I also think there is probably a way to shorten the table down to make it more efficient .~.

Any help would be appreciated... Oh, and I don't know if this will affect the outcome, but the NPC is animated.

0
You can use a for loop to loop through the 'Points' object, then have the current iteration object be added to the table via table.insert. TheeDeathCaster 2368 — 7y

1 answer

Log in to vote
2
Answered by 7 years ago

Alright, so there are a few things you could to make this easier. First of all, instead of making a table and specifying every point you can use a for loop OR use Roblox's useful built in method called GetChildren() which gets all the children of a model. And the reason your walk loop isn't working is because your for loop starts at 0 and in a table, there is no zero in a table BTWs before we go any further, Check to make sure your character model isn't anchored.

local points = game.Workspace.Points:GetChildren()
-- This will get all the children of the model in which the points are and Roblox uses C  for that so it will be a lot faster.
local current = 0
while true do
    wait()
    for i = 1,#points, 1 do
-- So now you start at 1 which is the first point instead of 0.
        current = current + 1
        script.Parent.Humanoid:MoveTo(points[current])
        repeat wait() until script.Parent.Humanoid.MoveToFinished(true)
    end
    current = 0
end
0
It worked :) Sort of... now the character does move. But it walks straight from the first point to the 4th in a straight line then it stops :( turtle2004 167 — 7y
Ad

Answer this question