Click on NPC and make them sit on a chair?

Hi!

How do I make a system where I click on a npc, and they will sit on a chair that is available? I’ve tried looking for a tutorial on that, but can’t seem to find any.

You could use the NPC’s Humanoid to make it sit on your seat.

local Seat = -- choose seat
local Humanoid = NPC:FindFirstChild("Humanoid")
Seat:Sit(Humanoid)

But what about the proximity prompt attached to them? How do I do it that if I interact with the npc’s proximity prompt then they will find a seat and walk to it and then sit.

ProximityPrompts have a Triggered event which you can use to detect it’s trigger.

local Seat = -- choose seat
local ProximityPrompt = -- choose prompt
local NPC = script.Parent -- choose npc

ProximityPrompt.Triggered:Connect(function()
    local Humanoid = NPC:FindFirstChild("Humanoid")
    Humanoid:MoveTo(Seat.Position)
    Humanoid.MoveToFinished:Wait()
    Seat:Sit(Humanoid)
end)

Make sure NOTHING conflicts with where the NPC is moving, or else it will stop moving…

1 Like

Do I put the local script in the Dummy or?

You should put it in the server (dummy) - all clients will see it

So in Serverscriptservice, right? or in workspace?

You can put it into the ProximityPrompt if you wanted, you will just have to define the three variables - Prompt, NPC, and Seat

Okay, so I did this, but the npc won’t move.

local Seat = workspace.Seat
local ProximityPrompt = script.Parent
local NPC = workspace.Dummy
ProximityPrompt.Triggered:Connect(function()

local Humanoid = NPC:FindFirstChild(“Humanoid”)
Humanoid:MoveTo(Seat.Position)
Humanoid.MoveToFinsihed:Wait()
Seat:Sit(Humanoid)
end)

Make sure to change NPC’s HumanoidRootPart Anchored property to false…

local Seat = workspace.Seat
local ProximityPrompt = script.Parent
local NPC = ProximityPrompt.Parent -- should be the npc


ProximityPrompt.Triggered:Connect(function()
	local Humanoid = NPC:WaitForChild("Humanoid")
	local HumanoidRootPart = NPC:WaitForChild("HumanoidRootPart")
	if HumanoidRootPart.Anchored then
		HumanoidRootPart.Anchored = false
		Humanoid:MoveTo(Seat.Position)
		Humanoid.MoveToFinished:Wait()
		Seat:Sit(Humanoid)
	end
end)

When you want the NPC to stand/sit, just make sure to unanchor the HumanoidRootPart beforehand. Also define the NPC starting from the ProximityPrompt (since it’s a child of NPC), not the workspace.

1 Like

I must be doing something wrong, I think. It still won’t move. Here’s a screenshot of my workspace:

Don’t use a LocalScript for this, use a Script. Also, I made a typo in the script but corrected it in the original post which you can copy from.

Where can Scripts and LocalScripts run from?

LocalScripts

Client code runs inside a LocalScript . This code will only start running if the LocalScript is a descendant of these instances:

  • A player’s Character model
  • A player’s PlayerGui
  • A player’s Backpack
  • A player’s PlayerScripts folder
  • A Tool (only when equipped by a player)
  • The ReplicatedFirst folder
Scripts

Server code runs inside a Script . This code will only start running if the Script is a descendant of these instances:

  • Workspace
  • ServerScriptService
  • A player’s Backpack

More info about this: Roblox Client-Server Model

I’m learning so much from you already! Thank you! It seems to be working now, but with a delayed start. I’ll click the proximity prompt and then 3 seconds later it moves to the seat instead of immediately.

Also, it only stands on the seat and not actually sit on it, I assume perhaps it may be the animation that needs to be assigned?

(Would you perhaps be interested in being my scripter? A paid offer, of course!)

Yeah, the Dummy will need a sitting animation like players do by default.

From the ‘Animate’ script.
R6 Sit - 178130996
R15 Sit - 2506281703
Both use a fade time of 0.5 seconds.

How do include this in my code?

I’d reccomend you get the Animate script from a player, copy it to the npc in studio, and change it to a script instead of a localscript while removing anything related to LocalPlayer