I am trying to make a script that will force the player to be seated during a cutscene, but the script I am using does not work?
-- Roblox services local Workspace = game:GetService("Workspace") -- Variables local seat = script.Parent local Classroom3 = seat.Parent.Parent local seatOccupant = seat.Occupant local CutscenePlayed = Classroom3:WaitForChild("CutscenePlayed") local CutsceneScript = Classroom3:WaitForChild("cutsceneScript") print("Test 1") local function startCutscene() print("Test 2") if CutscenePlayed.Value == false then CutsceneScript.Disabled = false while true do wait(0.1) seatOccupant.Sit = true end end seat:GetPropertyChangedSignal("Occupant"):Connect(startCutscene)
When I run this code, I get this error message: Attempt to index nil with 'Sit'
I don't really understand the error message. I know what nil is, but indexing?
All help will be appreciated greatly!
EDIT: I tried to print seatOccupant, but it printed nil.
Your missing something very simple. The character doesn't have a sit value. The Humanoid has a sit value
Try this
-- Roblox services local Workspace = game:GetService("Workspace") -- Variables local seat = script.Parent local Classroom3 = seat.Parent.Parent local seatOccupant = seat.Occupant local CutscenePlayed = Classroom3:WaitForChild("CutscenePlayed") local CutsceneScript = Classroom3:WaitForChild("cutsceneScript") print("Test 1") local function startCutscene() print("Test 2") if CutscenePlayed.Value == false then CutsceneScript.Disabled = false while true do wait(0.1) seat:Sit(InputPlayerHumanoid) end end seat:GetPropertyChangedSignal("Occupant"):Connect(startCutscene)
this is assuming that seat is some sort of a seat instead of a normal part