I’ve encountered this issue before, and based on the context, it’s most likely related to Streaming properties. I generally don’t recommend changing the streaming settings, as they can introduce other complications. Instead, I prefer finding workarounds.
From what I understand, Plane2 is a model, and inside it, there’s a part called “Seat”. The problem occurs because if the model is too far away, the model itself loads into the workspace, but its child parts do not. This causes them to return nil
, and no amount of WaitForChild
will fix it.
I’ve used two different methods to solve this:
-
Using Region3 – I didn’t attempt to find the part at all until the character was within a specific region, as looking for it beforehand was pointless.
-
Using
ChildAdded
– I listened for when the missing part was added to the model and referenced it then.
In your case, ChildAdded
method should work just fine. I previously implemented this successfully, and while I can’t find the exact script, I tested a new version, and it works fine.
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Workspace = game:GetService("Workspace")
local planeModelName = "Plane2" -- Name of the plane model
local plane = Workspace:FindFirstChild(planeModelName)
local seat
local KeyEvent = ReplicatedStorage:WaitForChild("BombFire")
local BombActivate = ReplicatedStorage:WaitForChild("BombActivate")
-- Function to update the seat reference when the plane spawns or loads
local function onPlaneAdded(model)
if model.Name == planeModelName then
print("Plane model has loaded!")
seat = model:FindFirstChild("Seat")
if not seat then
-- Listen for seat to be added dynamically
model.ChildAdded:Connect(function(child)
if child.Name == "Seat" then
seat = child
print("Seat has been found!")
end
end)
end
end
end
-- Check if the plane is already loaded, if not, wait for it to be added
if not plane then
Workspace.ChildAdded:Connect(onPlaneAdded)
else
onPlaneAdded(plane)
end
local function inputBegan(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode.R and seat and seat:FindFirstChild("SeatWeld") then
print("The player pressed R while sitting in the seat.")
KeyEvent:FireServer()
local Bomb = Instance.new("Part")
Bomb.Size = Vector3.new(1,1,1)
Bomb.Shape = "Ball"
Bomb.BrickColor = BrickColor.new("Deep orange")
Bomb.Material = Enum.Material.Neon
Bomb.Position = Workspace.Plane2:FindFirstChild("BombSpawn") and Workspace.Plane2.BombSpawn.Position or Vector3.new(0,0,0)
Bomb.Anchored = false
Bomb.CanCollide = true
Bomb.Parent = Workspace
BombActivate:FireServer(Bomb)
end
end
UserInputService.InputBegan:Connect(inputBegan)
I removed the bomb-related code from my test since it was irrelevant to verifying whether the seat appeared as nil
. Instead, I replaced the print statement for "Player pressed R"
with my own version.
To ensure the script worked correctly, I placed the model far away, so that the seat inside it wasn’t initially generated. When I walked close enough—or teleported near it—the seat loaded dynamically, and the script adjusted accordingly, detecting and adding the child as expected. Upon sitting in it and pressing R I had no issues.

*Edit: My buddy reminded me you can also adjust the Persistent
and PersistentPerPlayer
on the model as an alternative to make the children appear. I thought I’d post this here in case that is a better solution for you. Good looking out @JohhnyLegoKing