So I have this script that's supposed to give every person in the server a house. It kinda works except the last 2 players are given the same houses. Here's the script
local peopletohouse = game.Players:GetPlayers()
for a, b in pairs(peopletohouse) do
local homes = game.Workspace.Homes:GetChildren()
local house = homes[math.random(#homes)]
if house.Occupant.Value == "" then
house.Occupant.Value = b.Name
else
repeat
house = homes[math.random(#homes)]
until
house.Occupant.Value ~= ""
end
house.Occupant.Value = b.Name
house.Sign.SurfaceGui.TextLabel.Text = (house.Occupant.Value .. "'s Home")
print("Housed " .. b.Name .. " in " .. house.Name)
end
and here's the output
Housed Player1 in Home4 Housed Player2 in Home3 Housed Player3 in Home4 Housed Player4 in Home3 Housed Player5 in Home1 Housed Player6 in Home5 Housed Player7 in Home7 Housed Player8 in Home2
2 houses always end up housing 2 players. Any help?
