Script prints "nil"?

So basically I made a script that should tell when a player sits down. I want it to print the name of the chair they sat in. Bad news it always prints nil . So Im wondering why is this happing?

local planes = game:GetService('CollectionService'):GetTagged('Plane')

-- services
local uis = game:GetService('UserInputService')

-- player
local player =game:GetService('Players').LocalPlayer
local char = player.Character
local hum = char:FindFirstChildOfClass('Humanoid')

hum:GetPropertyChangedSignal('Sit'):Connect(function()
    local chair = hum.SeatPart -- this should be the chair that they sat in
    
    print(chair) 
end)
4 Likes

You should check if there is chair, because maybe it has a bit of delay and doesnt know what chair is

local planes = game:GetService('CollectionService'):GetTagged('Plane')

-- services
local uis = game:GetService('UserInputService')

-- player
local player = game:GetService('Players').LocalPlayer
local char = player.Character
local hum = char:FindFirstChildOfClass('Humanoid')

hum:GetPropertyChangedSignal('Sit'):Connect(function()
    local chair = hum.SeatPart -- this should be the chair that they sat in
    
    if chair then
        print(chair)
    else
        print("Not sitting in a chair.")
    end
end)

1 Like

maybe this will help

1 Like

Same result. Should I put this script in a different place? Rn its in StarterCharacterScripts

local hum = char:WaitForChild('Humanoid')

Probably this would work, also since its a script in startercharacterscript, char is also just script.Parent btw

1 Like

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