so whenever i test out my game click on the plane menu and spawn my plane i will walk up to it and when i try to sit in it by clicking e or standing on it the seat just doesn’t work it does nothing i have tried many things can anyone help here is the seat script:
"local Seat
local ClickDetector
– Function to wait for a model to be found in the Workspace
local function waitForModel(modelName, timeout)
local startTime = tick()
local model
while not model and tick() - startTime < timeout do
model = workspace:FindFirstChild(modelName)
wait(0.1) -- Adjust the wait time as needed
end
return model
end
– Function to find the Seat in the Plane model
local function findSeatInPlaneModel()
print(“Searching for the Plane model…”)
-- Find the Plane model in the Workspace
local Plane = waitForModel("Plane", 5) -- Wait up to 5 seconds
-- Check if Plane is found
if Plane then
print("Plane model found.")
-- Wait for a short period to allow replication of the Seat
wait(1) -- Adjust the delay time as needed
-- Find the Seat within the Plane model
Seat = Plane:FindFirstChild("Seat", true) -- Use the second argument 'true' to search recursively in descendants
-- Check if Seat is found
if Seat then
print("Seat found in the Plane model.")
-- Create a ClickDetector for the seat
ClickDetector = Seat:FindFirstChildOfClass("ClickDetector")
if not ClickDetector then
ClickDetector = Instance.new("ClickDetector")
ClickDetector.Parent = Seat
end
else
warn("Seat not found within the Plane model.")
end
else
warn("Plane model not found in the Workspace.")
end
end
local function setupSeat()
– Check if Seat and ClickDetector are found
if Seat and ClickDetector then
ClickDetector.MouseClick:Connect(function(player)
if player and player.Character and player.Character:FindFirstChild(“Humanoid”) then
local humanoid = player.Character:FindFirstChild(“Humanoid”)
-- Create a WeldConstraint between the HumanoidRootPart and the Seat
local humanoidRootPart = player.Character:WaitForChild("HumanoidRootPart")
local weld = Instance.new("WeldConstraint")
weld.Part0 = humanoidRootPart
weld.Part1 = Seat
weld.Parent = humanoidRootPart
else
print("Player, Character, or Humanoid not found.")
end
end)
else
print("Cannot set up Seat since it was not found.")
end
end
– Connect the findSeatInPlaneModel function to the PlayerAdded event
game.Players.PlayerAdded:Connect(function(player)
findSeatInPlaneModel()
setupSeat()
end)
– Run findSeatInPlaneModel and setupSeat immediately for players already in the game
for _, player in ipairs(game.Players:GetPlayers()) do
findSeatInPlaneModel()
setupSeat()
end
"