This is code is contained in a script, which is parented to a seat:
local players = game:GetService("Players")
script.Parent.Occupant.Changed:Connect(function ()
print(script.Parent.Occupant)
end)
However, when I test the place, I get this error: Workspace.Model.Seat.Script:2: attempt to index nil with 'Changed'
Why does this happen, and how do I fix it?
The error attempt to index nil with 'Changed' means you’re trying to access to an event from an instance that doesn’t exist. Make sure Occupant exists in the parent of your script.
If my explanation doesn’t solve your problem, send a screenshot of your explorer and more details.
local players = game:GetService("Players")
script.Parent:GetPropertyChangedSignal("Occupant"):Connect(function()
local Humanoid = script.Parent.Occupant
if Humanoid then
-- There's a player sitting
print(Humanoid)
end
end)