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

Why won't this humanoid walk to my character?

Asked by 8 years ago

Hello! So now I'm trying to make some scripted NPCs. So I have seen the way that some Zombie models work and how they walk to a humanoid. The script is very complicated though. So I decided to make my own simpler version! I actually made the base of this script using another model I made but Modified it. So basically when the player enters the NPC is supposed to walk to the player's position (Torso)

It doesn't work however. When I put the position of the torso, the NPC just walks to 0,0,0. But if I take the Position out and put it to a specific vector3. it walks to it. So I know it's working but I don't know why it won't walk tot he player. Any help?

game.Players.PlayerAdded:connect(function(p)--When a Player joins this function is triggered!
    p.CharacterAdded:connect(function(c)-- when a character is added (A physical robloxian) this function will be triggered! this also happens when you respawn!
        spawn(function()--When a character is spawned this function is triggered!
            while wait() do--This is an infinite loop!
                script.Parent.Humanoid.WalkToPoint = Vector3.new(c.Torso.Position) --Won't walk to this
            end
        end)
    end)
end)

3 answers

Log in to vote
1
Answered by
Redbullusa 1580 Moderation Voter
8 years ago

Why create a new vector, when the Torso's position is a vector property itself?

game.Players.PlayerAdded:connect(function(p)
    p.CharacterAdded:connect(function(c)
        spawn(function()
            while wait() do
                script.Parent.Humanoid.WalkToPoint = c.Torso.Position -- This is changed.
            end
        end)
    end)
end)
0
it wouldn't be Humanoid.WalkToPoint(c.Torso.Position)? dragonkeeper467 453 — 8y
0
Aha!! This works! I guess that would be simpler. Sorry for the long response, I had some things I had to take care of. Thanks! minikitkat 687 — 8y
0
You're welcome. Redbullusa 1580 — 8y
Ad
Log in to vote
1
Answered by 8 years ago

The reason is because you are saying Vector3.new(c.Torso.Position), That's like saying:

Vector3.new(Vector3.new(0,3.5,0))

You should use :MoveTo on the Humanoid instead of walk to point. NOTE If you use this on other objects like parts or models, It will teleport them.

Humanoid:MoveTo(Vector3.new(50,0,40)) --Walk to 50,0,40

This is the same thing as Redbullusa's Script except I used :MoveTo().

game.Players.PlayerAdded:connect(function(p)--When a Player joins this function is triggered!
    p.CharacterAdded:connect(function(c)-- when a character is added (A physical robloxian) this function will be triggered! this also happens when you respawn!
        spawn(function()--When a character is spawned this function is triggered!
            while wait() do--This is an infinite loop!
                script.Parent.Humanoid:MoveTo(Vector3.new(c.Torso.Position))
            end
        end)
    end)
end)



Hope it helps!

Log in to vote
0
Answered by 8 years ago

Try Humanoid.WalkToPart(c.Torso) as your no longer using a point, also, I think a problem may be that the torso is constantly moving, in that case you may want to use the standard method in zombie follow scripts which is below

--Try this on line 5 of your script posted above
Humanoid.WalkToPart(c.Torso) 

script.Parent.Humanoid:MoveTo(c.Torso.Position, c.Torso)
0
Humanoid.WalkToPart(c.Torso) WILL NOT WORK. WalkToPart is a Property so you have to treat it like one: Humanoid.WalkToPart = c.Torso . target is a function that isn't included in your script so adding the target part really had no purpose. EzraNehemiah_TF2 3552 — 8y
0
Ok, I took target out, sorry about that! dragonkeeper467 453 — 8y

Answer this question