[SOLVED] Why is it acting like a while loop?
Asked by
3 years ago Edited 3 years ago
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:
01 | for _, seat in pairs (bus.Bus.seats:GetChildren()) do |
03 | local Seat = seat.Seat |
04 | local occupant = Instance.new( "StringValue" , Seat) |
05 | occupant.Name = "CurrentOccupant" |
07 | Seat.Changed:Connect( function () |
08 | if not Seat.Occupant and not Seat.Disabled then |
10 | local plr = occupant.Value |
11 | local foundPlayer = false |
13 | if game:GetService( "Workspace" ):FindFirstChild(plr) then |
15 | plr = game:GetService( "Workspace" ) [ plr ] |
18 | if not foundPlayer then |
19 | print (plr, "left the game" ) |
21 | repeat wait() until not plr.Humanoid.Sit |
22 | plr.HumanoidRootPart.Position = bus.teleportPos.Position |
I found out that the reason if fires al the time is because th event changes Seat.Disabled, firing the event again.