#Can anyone tell me why the script is unable to find VehicleSeat

1 messages · Page 1 of 1 (latest)

simple lark
trim crane
# simple lark

When playing the game, if you check in the explorer, is VehicleSeat there?

That's a lot of code to look through, so it'd help if you just show the part where it attempts to find VehicleSeat

simple lark
# trim crane When playing the game, if you check in the explorer, is VehicleSeat there? That...

Fair enough will do:

local function setupCarListener(carModel: Model)
-- ... (Code inside the function below) ...
end

-- Gets the car model as input (e.g., Workspace.Car)
local bodyPart = carModel:FindFirstChild("Body")
-- Checks if 'Body' was actually found. If not, it stops processing this car.
if not bodyPart then return end


-- Now searches inside the 'bodyPart' found above
local driverSeat = bodyPart:FindFirstChildWhichIsA("VehicleSeat")
-- Checks if a 'VehicleSeat' was actually found inside 'bodyPart'. If not, it stops.
if not driverSeat then return end
trim crane
simple lark
#

Yea it is

wise roostBOT
#

studio** You are now Level 3! **studio

trim crane
# simple lark Yea it is

What if you print out the children of the body & print out the driverSeat variable? Just trying to rule some stuff out and debug a bit

simple lark
trim crane
# simple lark Debug output

Did you :WaitForChild since you're looking for the seat on the client? I know that isn't directly the same as FindFirstChildWhichIsA, but the seat may not replicate in time, so I'd want to analyze that

simple lark
#

will try to swap it out

#

I get this output

18:32:29.276 Stack End - Studio
18:32:32.991 Players.fru_buski.PlayerScripts.VehicleEntryController:135: attempt to call a nil value - Client - VehicleEntryController:135
18:32:32.991 Stack Begin - Studio
18:32:32.991 Script 'Players.fru_buski.PlayerScripts.VehicleEntryController', Line 135 - Studio - VehicleEntryController:135
18:32:32.991 Stack End - Studio

The lines in question here are

-- Setup Enter Prompt Listener
if not carPromptConnections[prompt] then
    carPromptConnections[prompt] = prompt.Triggered:Connect(function()
        if not isSeated and not isTransitioning then
            handleEnterCar(prompt)
        end
    end)
    prompt.Destroying:Connect(function()
        if carPromptConnections[prompt] then
            carPromptConnections[prompt]:Disconnect()
            carPromptConnections[prompt] = nil
        end
    end)
end
trim crane
simple lark
#

The places where WaitForChild are here was just changed from findfirstchildwhichisa to waitforchild

local function setupCarListener(carModel: Model)
local bodyPart = carModel:FindFirstChild("Body")
if not bodyPart then return end

local driverSeatInstance = bodyPart:WaitForChild("VehicleSeat", WAIT_TIMEOUT)
if not driverSeatInstance or not driverSeatInstance:IsA("VehicleSeat") then
    warn("VehicleEntryController: Failed to find a valid VehicleSeat named 'VehicleSeat' in", bodyPart:GetFullName())
    return
end
local driverSeat = driverSeatInstance :: VehicleSeat

local promptInstance = driverSeat:WaitForChild("ProximityPrompt", WAIT_TIMEOUT)
if not promptInstance or not promptInstance:IsA("ProximityPrompt") then
    warn("VehicleEntryController: Failed to find a valid ProximityPrompt named 'ProximityPrompt' in", driverSeat:GetFullName())
    return
end
trim crane
simple lark
#

Will try

#

Im getting srsly confused here

trim crane
#

are you trying to find a model inside the seat?

#

oh sorry nevermind

#

What's the event name constant?

simple lark
trim crane
# simple lark This?

No like the constant you use, what's the value of that? the one you use to search

simple lark
#

Oh 2 sec

#

ENTER_REMOTE_EVENT_NAME: The value is "EnterVehicleEvent".

EXIT_REMOTE_EVENT_NAME: The value is "ExitVehicleEvent".

trim crane
simple lark
#

Yeah

trim crane
# simple lark This is the entire output with debug prints

Ah okay, so we found the VehicleSeat fine. So printing those children aren't important anymore

So I guess we need to make sure we're looking for the event in the right spot.

It's a bit tough to look through all of that output on my phone, but maybe just a single print to say where it's looking from, and just one line here to tell me what the output was

simple lark
#

The script fails right after the line VehicleEntryController: > handleEnterCar - carModel found: Body. It then tries to run carModel:FindFirstChild("EnterVehicleEvent") and that fails.

So, the script thinks the variable carModel (which it got from seat:FindFirstAncestorOfClass("Model")) refers to the object named "Body". It's looking for the "EnterVehicleEvent" directly inside that object named "Body" according to the log, but it can't find it there.

And i just realized im stupid the EnterVehicleEvent isnt directly inside of Body its inside of Car

trim crane
simple lark
#

Well now i just get the fadein and fadeout i dont actually get in the car... I mustve just wrote everything wrong bro 😭

trim crane
simple lark
#

Yeah true