So I'm making a game and its basically like musical chairs. I have a script and I want it to count how many players there are and set how many seat there are. If there are 5 players there would be 3 seats etc. Its kinda hard to explain but this is the script ive got. The problem is is that it will remove the first seat and minus 1 from the Remaining Seats value but it will keep doing that and after it removes is (makes it transparent and changes thes can collide to false) Please help if you have any more info you need please ask. It is a server script in the serverscriptservice. No errors in output.
local count = script:FindFirstChild("Players")
local seats = game.Workspace.PlaneSeats
local remainingseats = script:FindFirstChild("RemainingSeats")
game.Players.ChildAdded:Connect(function(player)
count.Value = count.Value + 1
print(count.Value)
if count.Value == 1 then
repeat wait()
if seats.Seat1.SeatPart.Occupant ~= "Humanoid" then
seats.Seat1.Transparency = 1
seats.Seat1.CanCollide = false
seats.Seat1.Archivable = false
seats.Seat1.SeatPart.Disabled = true
remainingseats.Value = remainingseats.Value - 1
elseif seats.Seat2.SeatPart.Occupant ~= "Humanoid" then
seats.Seat2.Transparency = 1
seats.Seat2.CanCollide = false
seats.Seat2.Archivable = false
seats.Seat2.SeatPart.Disabled = true
remainingseats.Value = remainingseats.Value - 1
elseif seats.Seat3.SeatPart.Occupant ~= "Humanoid" then
seats.Seat3.Transparency = 1
seats.Seat3.CanCollide = false
seats.Seat3.Archivable = false
seats.Seat3.SeatPart.Disabled = true
remainingseats.Value = remainingseats.Value - 1
elseif seats.Seat4.SeatPart.Occupant ~= "Humanoid" then
seats.Seat4.Transparency = 1
seats.Seat4.CanCollide = false
seats.Seat4.Archivable = false
seats.Seat4.SeatPart.Disabled = true
remainingseats.Value = remainingseats.Value - 1
elseif seats.Seat5.SeatPart.Occupant ~= "Humanoid" then
seats.Seat5.Transparency = 1
seats.Seat5.CanCollide = false
seats.Seat5.Archivable = false
seats.Seat5.SeatPart.Disabled = true
remainingseats.Value = remainingseats.Value - 1
elseif seats.Seat6.SeatPart.Occupant ~= "Humanoid" then
seats.Seat6.Transparency = 1
seats.Seat6.CanCollide = false
seats.Seat6.Archivable = false
seats.Seat6.SeatPart.Disabled = true
remainingseats.Value = remainingseats.Value - 1
elseif seats.Seat7.SeatPart.Occupant ~= "Humanoid" then
seats.Seat7.Transparency = 1
seats.Seat7.CanCollide = false
seats.Seat7.Archivable = false
seats.Seat7.SeatPart.Disabled = true
remainingseats.Value = remainingseats.Value - 1
elseif seats.Seat8.SeatPart.Occupant ~= "Humanoid" then
seats.Seat8.Transparency = 1
seats.Seat8.CanCollide = false
seats.Seat8.Archivable = false
seats.Seat8.SeatPart.Disabled = true
remainingseats.Value = remainingseats.Value - 1
elseif seats.Seat9.SeatPart.Occupant ~= "Humanoid" then
seats.Seat9.Transparency = 1
seats.Seat9.CanCollide = false
seats.Seat9.Archivable = false
seats.Seat9.SeatPart.Disabled = true
remainingseats.Value = remainingseats.Value - 1
elseif seats.Seat10.SeatPart.Occupant ~= "Humanoid" then
seats.Seat10.Transparency = 1
seats.Seat10.CanCollide = false
seats.Seat10.Archivable = false
seats.Seat10.SeatPart.Disabled = true
remainingseats.Value = remainingseats.Value - 1
end
until remainingseats.Value == 1
print("Done!")
end
end)
game.Players.ChildRemoved:Connect(function(player)
count.Value = count.Value - 1
print(count.Value)
end)
