Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Problems with getting character/humaniod (for Humanoid.Sit property) (?)

EDIT: The problem has been resolved!: Check the other answer/ comment written by myself, below.

Hey there. I was trying to get a certain seat part whenever a humanoid/ player would sit on it. So I check out the wiki: https://developer.roblox.com/en-us/api-reference/event/Humanoid/Seated

And found the "Humanoid.SeatPart", that sounded like just what I needed. But before trying out the "Humanoid.SeatPart" property, I first wanted to test the "Humanoid.Sit" property.

So I made a Local Script in the StarterPack, and a Seat object in Workspace.

This is the code that I used:

if game.Players.LocalPlayer.Character.Humanoid.Sit==true then
	        print "Character is sitting"
		else
	        print "Character is not sitting"
end

The code is super simple, and I have no clue why it doesn't work...

The Output says:

" Players.henrikknudsen.Backpack.LocalScript:1: attempt to index field 'Character' (a nil value)"

Thanks in advance! :-)

6 comments

0

I entered the part of your error after the colon and found the solution to your problem. https://scriptinghelpers.org/questions/11042/attempt-to-index-field-field-character-a-nil-value

0

Please don't ask a question if the answer can be found with a google search.

0

Especially when it's the first thing that pops up...

0

Trust me, I wouldn't post some mindless question before doing some research on beforehand. Actually, I hadn't seen the link that you just sent (but I have been checking a lot of other places). But the answers in that thread doesn't help me fix my problem. I corrected my script a bit my applying the "local player = game:GetService'Players'.LocalPlayer" and

0
  • “local character = player.Character or player.CharacterAdded:Wait()” parts. But when I try to get the Humaniod by writing: “local humaniod = character.Humaniod” I just get an output of: “Humaniod is not a valid member of Model”. I was afraid my question wouldn’t be taken seriously because it is such a simple one – but it still causes me a lot of trouble! :(
0

So, if you or anyone else could help me fix it, I would really appreciate it!

1 answer

Little update: I have now tried using a line of code from the Roblox Developer Hub/ Roblox Dev wiki. link: (https://developer.roblox.com/en-us/api-reference/event/Humanoid/Seated) - at the bottom of the page. (And yes, I placed the code in a Local Script and parented it to the StarterPlayer.StarterPlayerScripts).

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
 
humanoid.Seated:Connect(function(isSeated, seat)
	if isSeated then
		if seat then
			print ("The player is now sitting in the seat named "..seat.Name.."!")
		end
	else
		print("The player is no longer sitting!")
	end
end)

The code, despite being on the wiki, also doesn't work. Could this have been caused by some Roblox update? Or did both Roblox and I make the same mistake?

EDIT: The problem has been resolved!! :D Apparently you had to place the Local Script in "StarterPlayer.StarterCHARACTERScripts" instead of "StarterPlayer.StarterPLAYERScripts"!

This discussion is preserved as it was. New answers, comments, and votes are closed.