Today I was writing a for loop for my boat script that makes you sit on a seat that is currently free. However my script thinks there is only one seat.
My code:
enterBoat.Touched:Connect(function(touch)
if touch.Parent:FindFirstChild("Humanoid") ~= nil then
local humanoid = touch.Parent:FindFirstChild("Humanoid")
for _, seat in pairs(boat2.Seats:GetChildren()) do
if seat.Occupant == nil then
humanoid.Parent:FindFirstChild("HumanoidRootPart").Position = seat.Position
seat:Sit(humanoid)
ShowBoatUIEvent:FireClient(Players:GetPlayerFromCharacter(humanoid.Parent), true)
seat.Changed:Connect(function(property)
if property == "Occupant" and not seat.Occupant then
humanoid.Parent:FindFirstChild("HumanoidRootPart").Position = boatExit.Position
ShowBoatUIEvent:FireClient(Players:GetPlayerFromCharacter(humanoid.Parent), false)
end
end)
break
end
end
end
end)
It’s just a for loop iterating over the seats and making you sit on the first free one.
I have checked my code many times and I couldn’t find anything. Can you tell me why my loop doesn’t work thx?