Having issues with making Humanoid.Sit

Hello everyone. I am pretty new to scripting and am having a bit of trouble with what I am trying to do. I attempted to make a button that will make the player who clicks it, sit down. The player will go flying down a pile of stairs. :laughing: Here is my script:

local button = script.Parent
local plr = game.Workspace:FindFirstChild(“Humanoid”)

button.MouseButton1Down:Connect(function(trip)
if trip then
plr.Sit = true
end
end)

When I press the button to trigger this script, it pops up in the output with “attempt to index nil with ‘Sit’”.
Not really sure what to do…

Is the button a ClickDetector?

It is not in fact. Just a regular GUI textbutton.

Oh. I did not know that. What is the easiest way to get a Humanoid to sit by pressing a GUI button?

You aren’t getting the player’s humanoid. You are only looking for a humanoid inside the workspace. If this is a GUI, you need to get the player’s character by doing this:

local LocalPlayer = game.Players.LocalPlayer
local character = LocalPlayer.Character
local Humanoid  = character:WaitForChild("Humanoid")
1 Like

The Sit property of the humanoid can be toggled to true or false. It doesn’t say that it’s read-only.

What you are doing is correct, it’s just that you aren’t getting the player’s character and the player’s humanoid properly.

1 Like

Nevermind just noticed i was wrong your getting the humanoid incorrectly instead do this:

local button = script.Parent
local plr = game.Players.LocalPlayer

Button.MouseButton1Down:Connect(function()
      local Character = plr.Character or plr.CharacterAdded:Wait()
      local Humanoid = Character and Character:FindFirstChild("Humanoid")
      Humanoid.Sit = true
end)
1 Like

Ohhhh this makes a LOT more sense! Thank you so much, I really appreciate your time. My script successfully ran how I needed it to. :smiley:

1 Like

Use my method @Quwanterz will not work if the character dies or resets.

I am a bit confused by why it would not work, maybe a little bit of elaboration, please.?Just reseted my character and the button still worked fine.

Do you have the resetonspawn property of screen gui ,parented to the button, to true, if yes then that’s why it works