Help with my seat code

Oh sorry i forgot to update the script i edited it after i noticed it was a little broken uhh maybe this should work if it doesnt im really confused on why

local Seats = {
	game.Workspace.Couch1.Seat1,
	game.Workspace.Couch1.Seat2,
}
local Players = game:GetService("Players")

function SeatOccupied(Seat)
	local weld = Seat:FindFirstChild("SeatWeld")
	if weld then
		return weld
	end
end

Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(character)
		spawn(function()
			local hrp = character:WaitForChild("HumanoidRootPart")
			local AvailableSeats = {}
			for _,v in pairs(Seats) do
				if not SeatOccupied(v) then
					table.insert(AvailableSeats,v)
				end
			end
			local PickedSeat
			if #AvailableSeats > 0 then
				PickedSeat = AvailableSeats[math.random(1,#AvailableSeats)]
				hrp.CFrame = PickedSeat.CFrame
			else
				PickedSeat = Seats[math.random(1,#Seats)]
				hrp.CFrame = PickedSeat.CFrame * CFrame.new(0,SeatOccupied(PickedSeat).Part1.Size.Y + 1 + hrp.Size.Y,0)
			end
		end)
	end)
end)

do I remove the original script i own

yeah this script will replace it. btw you can change the Seat table to have the seats you want

thanks so much it works and also if i was able to add more seats and stuff do i just add on to the
game.workspace.2ndcouchname.2ndseatname and it would still work

and sorry to ask to much but is there away to where i can make it like spawn me right away instead of me falling outside the place then spawning there. I dont want people in my game to see the outside of map

yea u can add more seats to that like this


local Seats = {

workspace.TestSeat1,

workspace.TestSeat2,

workspace.TestSeat3,

-- and add some more if u want just dont forget the comma at the end of each of them

}

it might be because the script is on the server side and client responds a little late to the teleport but i could make it local script

you can do that but i dont want to waiste your time

oh ok well i hope your game development goes well

and quick question if i was to make it a local script i just paste it in there right and it works like that

It would need a little modification but fortunately this one isnt hard to change for local script so here

local Seats = {
	game.Workspace.Couch1.Seat1,
	game.Workspace.Couch1.Seat2,
}
local character = script.Parent
local hrp = character:WaitForChild("HumanoidRootPart")

function SeatOccupied(Seat)
	local occupant = Seat.Occupant
	return occupant
end

function teleportToSeat()
	local AvailableSeats = {}
	for _,v in pairs(Seats) do
		if not SeatOccupied(v) then
			table.insert(AvailableSeats,v)
		end
	end
	local PickedSeat
	if #AvailableSeats > 0 then
		PickedSeat = AvailableSeats[math.random(1,#AvailableSeats)]
		hrp.CFrame = PickedSeat.CFrame
	else
		PickedSeat = Seats[math.random(1,#Seats)]
		hrp.CFrame = PickedSeat.CFrame * CFrame.new(0,SeatOccupied(PickedSeat).Parent.PrimaryPart.Size.Y + 1 + hrp.Size.Y,0)
	end
end

teleportToSeat()

btw put this inside a local script in StarterPlayer>StarterCharacterScripts

I will try right now to see if it works thanks

doing that code just tp me out of map and does nothing else

wait hold on i forgot to fix something

i realized i put everything in a folder so i need to fix those. just give me a min

remember to locate the seat parts inside the Seat table

wdym by that. The code does work fine for me now but I just want to know bec maybe that will fix it from me still loading outside but only for like few seconds

oh its just when i said this earlier but im assuming you know how tables work. also idk why ur still outside for a little bit maybe just cuz ur character is loading

I can just send a video so you know what im talking about. Just give me a few seconds

nvm its fine but now its not sitting my chracter