Seat not working on a plane that i am working on

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
"

2 Likes

btw here is an image of how everything looks
Schermafbeelding 2023-11-19 192057

1 Like

i am printing stuff to find the error but it cant find the plane model in workspace while it is in workspace
Schermafbeelding 2023-11-19 192316

1 Like

The plane model isn’t located in the workspace, but in the PartsFolder, in the workspace.

local function findSeatInPlaneModel()
	print("Searching for the Plane model…") -- Searches for the PartsFolder folder

	-- Find the Plane model in the Workspace
	local PartsFolder = waitForModel("PartsFolder", 5)  -- Wait up to 5 seconds
	
	if not PartsFolder then warn("Parts Folder not found."); return end -- If the PartsFolder folder isn't found, warns and returns end.
	
	local Plane = PartsFolder:FindFirstChild("Plane")

	-- 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 Parts Folder.")
	end
end

good luck on your game

thanks but this doesn’t work it still doesn’t let me sit in the Seat btw i got no errors to

Seat parts have a :Sit() function

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")
				Seat:Sit(humanoid)
			else
				warn("Player, Character, or Humanoid not found.")
			end
		end)
	else
		warn("Cannot set up Seat since it was not found.")
	end
end

ok i am gonna try this ill tell you if it works or not

it doesn’t recognize the clickdetector and the Seat global

You can try to use “Output” on view category to see where the problem is (Im not really into scripting but I think you colud make a spelling mistake in the script, which is hard to spot)

i am using the output since i have started making the script so don’t worry about that

Can you format the entire code more properly since it’s hard to read and send the console of what happens when you try to sit?

these are some prints but no errors and it still wont let me sit

20:33:54.800 MyGui - Client - LocalScript:11
20:33:54.800 MenuFrame - Client - LocalScript:12
20:33:57.681 Button clicked - Client - LocalScript:24
20:33:58.548 Button clicked - Client - LocalScript:63
20:33:58.548 Model found - Client - LocalScript:70
20:33:58.548 cloneAndMove function called - Client - LocalScript:20
20:33:58.548 Object type: Model - Client - LocalScript:21
20:33:58.551 End of cloneAndMove function - Client - LocalScript:58
20:34:02.913 Seat not found within the timeout period. - Server - Script:84

the script:

local ClickDetector
local Seat

– Function to wait for a specific child within a parent with a timeout
local function waitForChild(parent, childName, timeout)
local startTime = tick()
local child

repeat
    child = parent:FindFirstChild(childName)
    wait(0.1)
until child or tick() - startTime >= timeout

return child

end

– Function to find the seat within the Plane model
local function findSeatInPlaneModel()
print(“Searching for the Plane model…”)

local partsFolder = waitForChild(workspace, "PartsFolder", 5)

if not partsFolder then
    warn("Parts Folder not found.")
    return
end

local plane = partsFolder:FindFirstChild("Plane")

if not plane then
    warn("Plane model not found in the Parts Folder.")
    return
end

print("Plane model found.")

wait(1)  -- Adjust the delay time as needed

Seat = plane:FindFirstChild("Seat", true)  -- Use the second argument 'true' to search recursively in descendants

if Seat then
    print("Seat found in the Plane model.")
    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

end

– Function to set up the seat
local function setupSeat()
if Seat and ClickDetector then
local function onSeatClicked(player)
local humanoid = player.Character and player.Character:FindFirstChild(“Humanoid”)

        if humanoid and Seat:FindFirstChild("HumanoidSeat") then
            Seat.HumanoidSeat:Sit(humanoid)
        else
            warn("Player, Character, or Humanoid not found.")
        end
    end

    ClickDetector.MouseClick:Connect(onSeatClicked)
else
    warn("Cannot set up Seat since it was not found.")
end

end

– Example: Use waitForChild to find the seat
Seat = waitForChild(workspace, “YourSeatName”, 10)

– Check if the seat is found before proceeding
if Seat then
ClickDetector = Seat:FindFirstChild(“ClickDetectorName”)

-- Call functions to set up the seat
findSeatInPlaneModel()
setupSeat()

else
warn(“Seat not found within the timeout period.”)
end

you need to click the seat to sit, as it has a ClickDetector, not trigger the ProximityPrompt

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 seat in plane
local function findSeatInPlaneModel()
	print("Searching for the Plane model…") -- Searches for the PartsFolder folder

	-- Find the Plane model in the Workspace
	local PartsFolder = waitForModel("PartsFolder", 5)  -- Wait up to 5 seconds

	if not PartsFolder then warn("Parts Folder not found."); return end -- If the PartsFolder folder isn't found, warns and returns end.

	local Plane = PartsFolder:FindFirstChild("Plane")

	-- 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 Parts Folder.")
	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")
				Seat:Sit(humanoid)
			else
				warn("Player, Character, or Humanoid not found.")
			end
		end)
	else
		warn("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

even when clicking on it, it wont work it just won’t let me sit while if i make a seat unanchored on the ground it will let me sit

Can you record it? I wanna see how it looks like.

the file size is to long bruh so i cant post it here

like i can only sit in the anchored plane but not in the unanchored plane and the anchored plane is in the folder called FolderParts and the unanchored plane gets copied from the FolderParts folder and gets placed into workspace without the FolderParts folder as parent so i think that might be the issue but idk how to do that

How about you make the sit function inside the seat and not via server? Try removing the setupSeat() function or whatever it was called and put this script into the seat:

local cd = Instance.new("ClickDetector")
cd.Parent = script.Parent

cd.MouseClick:Connect(function(player)
	if player and player.Character and player.Character:FindFirstChild("Humanoid") then
		local humanoid = player.Character:FindFirstChild("Humanoid")
		script.Parent:Sit(humanoid)
	else
		warn("Player, Character, or Humanoid not found.")
	end
end)

image

if i hold e or try to click on the sit part or stand on it it just wont let me btw just to let you know i am playtesting rn and everytime i spawn a plane it is not in the folderparts thing so that might be the problem i think
Schermafbeelding 2023-11-19 211607