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

How to make a custom made NPC follow a player and have an animation doing so?

Asked by 4 years ago

I am new to scripting, and I have searched all over the web for this answer. I really need this for a new game I'm making, and yes I already have the animation ready for my game.

1 answer

Log in to vote
0
Answered by
Dfzoz 489 Moderation Voter
4 years ago

You should at least try to make it. I will give you some references:

-Make a while true do loop that isnt so frequent (with a wait time of about 5 seconds is good I guess)

-Reference your NPC. Also reference the character, like this: local char = game.Players.TargetPlayer.Character or game.Players.TargetPlayer.CharacterAdded:Wait(). This way of referencing is good to avoid bugs when character isn't available and also avoid loops with too much frequency.

-Check if character and NPC aren't nill. If nill then repeat the wait for character to reference it or spawn a new NPC and reference it too. Then, check if their distance isn't too far.

Example: if (character.HumanoidRootPart.Position-NPC.HumanoidRootPart.Position).magnitude < 50 then walkfunction end)

-Use Humanoid:MoveTo() when the checks are passed and set the position to your character position, then it will follow you.

-You can make it teleport close to you if its too far away. In this case you can use "else" on the distance check and set the CFrame of the NPC to your character position.

-If you want the enemy to follow you but not so that it gets close enough to touch you, like a zombie, then you can use (character.HumanoidRootPart.Position+character.HumanoidRootPart.CFrame.rightVector*5) on the checks, the humanoid:MoveTo() function and the CFrame teleport, which will in that case make the NPC move 5 studs to your right.

0
Hey, by new to scripting i meant VERY new... no idea what any of this means ;-; IAmFancyBobert 0 — 4y
0
I started learning to script by getting free models I wanted to use and messing with their scripts. You can find an animated Zombie free modell (which I get a lot because I think it takes too much time to do a animation script) and look at their follow script. You will find that it is similar to what I said. Dfzoz 489 — 4y
0
So I have a model ready, do I just completely trash it and work on the zombie? IAmFancyBobert 0 — 4y
0
I dont know, you could try putting the zombie script on your model. Maybe it will work Dfzoz 489 — 4y
Ad

Answer this question