Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I can't set the value why?

--|| 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

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

This discussion is preserved as it was. New answers, comments, and votes are closed.