Lobby not working

Hey Everyone,
I’m making a seater for my story game,
Here is my script:

Hitbox.Touched:Connect(function(Hit)
	print('hit')
	if Hit.Parent:FindFirstChild('Humanoid') then
		print('Humanoid')
		local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
		local humanoid = Player.Character.Humanoid
		if not table.find(BusTable, Player) and Teleporting == false then
			print('Not found')
			for _, seat in pairs(Seats:GetChildren()) do
				if seat.Occupant == nil then
					seat:Sit(humanoid)
					humanoid.JumpPower = 0
					table.insert(BusTable, Player)
				end
			end
		end
	end
end)

I get no errors, thanks for any help!

I see you have debug prints. Does it print ‘Not Found’?

It inserts them into the table and sets their jumppower to 0 but just doesn’t put them in the seat.

Try teleporting them to the Seat’s position. That could possibly help.

I’ve never used any table.find but I could try to answer your question with a different piece of code:

local inBus = {}
local hitBox = -- yes put it here
local seats = --  ^^^^^^^^^^^^^^^

hitBox.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	
	if player then
		local humanoid = hit.Parent:FindFirstChild("Humanoid")
		local inBusTable = false
		
		for _,v in pairs(inBus) do
			if v == player.Name then
				inBusTable = true
			end
		end
		
		if inBusTable == false then
			for _,v in pairs(seats:GetChildren() do
				if v.Occupant == nil then
					v:Sit(humanoid)
					table.insert(inBus, player.Name)
				end
			end
		end
	end
end)

**

-- Be sure when leaving

inBus = {}

I’m sure it’s something to do with

seat:Sit(humanoid)

As the jumppower sets to 0 and it adds them to the table.

You’ve done the seat:Sit() correctly as long as the humanoid isn’t nil.

No, it is a normal Seat method. Check it out here.

I wanna mention some things first:

  1. local humanoid = Player.Character.Humanoid can just be:
local humanoid = hit.Parent:FindFirstChild("Humanoid")
  1. It seems like you didn’t break the loop in the Seats:GetChildren() resulting in being sitted to every seat, you should do break once the condition is met.
2 Likes

This is one of my old code snippets. It worked.

randomSeat.Seat:Sit(player.Character.Humanoid)
	workspace.BlueBus.PlayersInBus.Value = workspace.BlueBus.PlayersInBus.Value + 1
	player.Character.Humanoid.JumpPower = 0

There must be problem with your if-logic.

Excuse the spacing. It’s old.

Seems like that made it work(adding the break in)

1 Like