I want to prevent NPCs from sitting in chairs or passenger seats, is there a way

I want to prevent NPCs from sitting in chairs or passenger seats, is there a way

2 Likes

Its easy! First check if the player is a real player, do this by GetPlayerFromCharacter().
Like so,

local part = game.workspace.PART -- change part to your seat


part.Touched:connect(fuction(hit) 
      local player = game.Players.GetPlayerFromCharacter(hit.parent) -- checks if hit.parent is a real player
      if player then
        hit.parent.FindFirstChild("Humanoid").Sit = true -- if it is a real player then this will make the player sit
     else
        hit.parent.FindFirstChild("Humanoid").Sit = false -- if not player then it won't sit and the script will make npc not sit
end)
2 Likes

Let me know if you face some errors

If you don’t want them to sit at all just disable the Seated state on the humanoid.

See Humanoid | Roblox Creator Documentation

NPC.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Seated, false)

This will entirely prevent the NPC from sitting in seats.

2 Likes

Workspace.yfsonata.Body.Seats.1.Script:13: attempt to index nil with ‘Sit’

It seems to work, but this error appears.

It works perfectly. Thank you.It works perfectly. Thank you.It works perfectly. Thank you.

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