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’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)
local humanoid = Player.Character.Humanoid can just be:
local humanoid = hit.Parent:FindFirstChild("Humanoid")
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.