NPC that request things

I have npcs that spawn randomly, but I want them to request things. Like a gui that shows over their heads saying they want an apple and the player has to give it to them.

This is what I have so far.

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

randomnpc.Parent = workspace
randomnpc.PrimaryPart.CFrame = game.Workspace.Spawnparts.RED.CFrame 
randomnpc.Humanoid:MoveTo(game.Workspace.Spawnparts.BLUE.Position)
print("works!")

Hi, bumping this up. Any help is very much apppreciated :slight_smile:

Use a billboard gui above the npc’s head. Then you can help a click detector or proximity prompt for the player to press once they have a certain tool. The script will check if the player has the tool.

If you have any specific code your having trouble with, lmk.

I have this atm, but it’s not working. I’m not sure how else to add the billboard gui. Could you please help? :slight_smile:

local proximityPrompt = script.Parent

proximityPrompt.Triggered:Connect(onTriggered)
local function onTriggered(player)
	local leaderstats = player.leaderstats

	if leaderstats.Apples.Value >= 1 then
		leaderstats.Apples.Value -= 1
		leaderstats.Money.Value += -- Amount
	end
end

Here’s the issue with that script.

On line 3, “onTriggered” is out of the scope.
This essentially means that “onTriggered” has not been defined in the script yet.
Connect the function after the function is declared.

For Billboard guis:

I am bumping this post again, any help is very much appreciated :slight_smile:

You could just use the ChatService to have a chat bubble above the NPC’s head:

local NPCHead= -- Path to NPCs head model
local ChatBox=game:GetService("Chat")
ChatBox:Chat(NPCHead, "Hello, could you give me an apple?"
1 Like

I prefer to use billboard GUI with icons for players who are illiterate/kids etc… :slight_smile:

1 Like