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

I can't set the value why?

Asked by 3 years ago
--|| This is the script its erroring at the line after "Found a seat" ||--
local Prompt = script.Parent
local ActionText = "Hold F to join the car"
local HoldDuration = .8
local MaxActivationDistance = 7.5

Prompt.ActionText = ActionText
Prompt.ClickablePrompt = true
Prompt.HoldDuration = HoldDuration
Prompt.KeyboardKeyCode = Enum.KeyCode.F
Prompt.MaxActivationDistance = MaxActivationDistance
Prompt.ObjectText = "Join the car"
Prompt.RequiresLineOfSight = true

local BackSeats = script.Parent.Parent["Back Seats"]

Prompt.Triggered:Connect(function(Player)
    local Character = Player.Character
    if Character then
        for _, seat in pairs(BackSeats:GetChildren()) do
            if seat.Occupant == nil then
                print("Found a seat")
                seat.Occupant = Character.Humanoid
                break
            end
        end
    end
end)

Error: Can't set the value

2 answers

Log in to vote
0
Answered by
yx10055 57
3 years ago

https://developer.roblox.com/en-us/api-reference/property/Seat/Occupant This property can only be read from. Attempting to write to it will cause an error.

Ad
Log in to vote
0
Answered by 3 years ago

Like yx10055 correctly said, you cannot set the seat occupant. Instead replace lines 21-25 with the following code.

if seat.Occupant then return end --Make sure seat is empty

if not Character then return end --Check for character

local humanoid = Character:FindFirstChild("Humanoid")

if not humanoid then return end --Check for humanoid

seat:Sit(humanoid) --Player sits if seat is empty, character exists, and humanoid exists

Answer this question