Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to force player to be seated?

Asked by 4 years ago
Edited 4 years ago

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.

0
Put in a server script: Humanoid:Sit(*insert seat here*) torchmaster101 92 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

Your missing something very simple. The character doesn't have a sit value. The Humanoid has a sit value

Ad
Log in to vote
0
Answered by 4 years ago

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

Answer this question