So I am currently making this script for someone and there is something wrong Whenever the .Changed event gets fired it Basically automaticly puts everything inside the event into a while loop and the event repeats itself forever.
Why is this please help
Code:
for _, seat in pairs(bus.Bus.seats:GetChildren()) do
local Seat = seat.Seat
local occupant = Instance.new("StringValue", Seat)
occupant.Name = "CurrentOccupant"
Seat.Changed:Connect(function()
if not Seat.Occupant and not Seat.Disabled then
Seat.Disabled = true
local plr = occupant.Value
local foundPlayer = false
if game:GetService("Workspace"):FindFirstChild(plr) then
foundPlayer = true
plr = game:GetService("Workspace")[plr]
end
if not foundPlayer then
print(plr, "left the game")
else
repeat wait() until not plr.Humanoid.Sit
plr.HumanoidRootPart.Position = bus.teleportPos.Position
end
Seat.Disabled = false
end
end)
end
I found out that the reason if fires al the time is because th event changes Seat.Disabled, firing the event again.

2 comments
Check Seat.Occupant (https://developer.roblox.com/en-us/api-reference/property/Seat/Occupant)
if its nil