Npcs that spawn and request things from player's leaderstats

Hi,

I would like to make npcs that spawn randomly and request things for example an egg, the player has eggs in their leaderstats and when they player proximity clicks on npc, the egg will remove from
leaderstats and the npcs gives money by adding that to the player’s leaderstats.

How do I begin making this?

2 Likes

Step 1 would IMO be figuring out how to work with proximity prompts. How to set them up in the world, and how to run a function when a prompt is activated.

1 Like

I know how proximity prompts work, but I imagine the toughest part is making the npcs request something from the player’s leaderstats which in this case is an egg.

Can you just look for that lesderstat in the player folder and check for that specific leaderstat?

Hi, I have the leaderstats already.

I have this already. Now I just need them to spawn at Part A and walk up to part B

local folder = game.ServerStorage.NPCS
local randomnpc = folder:GetChildren()[math.random(#folder:GetChildren())]

set position to part a then use move to to part b

I have this but the npc won’t move at all.

local folder = game.ServerStorage.NPCS 
local randomnpc = folder:GetChildren()[math.random(#folder:GetChildren())]

randomnpc.Parent = workspace
randomnpc.PrimaryPart.CFrame = game.Workspace.Spawnparts.RED.CFrame 

repeat wait() until game.Loaded
randomnpc.Humanoid:MoveTo(game.Workspace.Spawnparts.BLUE.Position)
print("works!")

I think move to only works with models

Something like

model:MoveTo

Theres an article in the documentation about pathfinding here- check it out i think itll be good for what u need