How would I make an NPC that does the following?

I have very little experience with interactive NPCs/non-player humanoids.

I am making a new game in which players would have access to a garage. I am looking at adding an NPC to the garage, in which this NPC would do the following:

  • Wave at the player, in a loop, as long as the player is within range of the NPC and hasn’t interacted with the player yet (interaction would be through a ProximityPrompt which I have experience with). The NPC waving at one player would not be seen by other players that are not within range, unless other players also came within range. I am aware that this would require a local script at the very least, which I have experience with, and mild animating, which I don’t have much experience with, but it would be a simple animation that I could definitely figure out myself.

  • Stop waving at the player once the player triggers a ProximityPrompt that would be in the NPC’s torso, and a GUI would spawn (this is how players would spawn vehicles). NPC would just stand there while the player does whatever on this GUI. Once the player has closed the GUI by either spawning a vehicle or otherwise closing the GUI, the NPC would once again go back to waving at the player.

  • The entire time the player is within range of the NPC, the NPC would angle/orient itself towards the direction of where the player is moving/coming towards. For example, if the player is coming head on to the NPC but suddenly makes a slight right, the NPC would orient itself towards the player’s right, which would be its left. Once again, the NPC would only do this for the individual player, so if there is one player on its right and one on its left, the NPC would be facing the respective direction for each respective player. I am aware that this would require some usage/knowledge of CFrame angles which I don’t have a whole lot of, and I assume that this would also need raycasting to determine where the player is coming from? I may cut out this requirement since it is pretty complex and probably unnecessary, but it would be cool.

The documentation page for ProximityPrompt is very useful for what you are trying to do

ProximityPrompt | Roblox Creator Documentation

  • Use ProximityPrompt.PromptShown and ProximityPrompt.PromptHidden to play and stop the NPC’s waving animation
  • Manually hide the proximity prompt when it is activated and then show it again when the menu is closed using ProximityPrompt.Enabled
  • Set a boolean variable to true or false using the above events to represent whether or not the character is currently within range. Then in a runservice loop set the CFrame of the NPC to CFrame.new(npcPosition, playerPosition) if the boolean variable is set to true

To set all of this up you may want to create a LocalScript in StarterPlayerScripts. Tag the NPC model with a CollectionService tag and then make the LocalScript set up NPCs with the tag to conform with the above behavior.

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.