So I'm trying to make a game like horrific housing, where houses will spawn for every player in the server, so 3 players 3 houses will spawn, and I have wrote some code and a table incase I need to use a table for this, but the code won't work, it's not giving me any errors in the output.
local Houses = { [1] = game.ServerStorage.House1, [2] = game.ServerStorage.House2, [3] = game.ServerStorage.House3, [4] = game.ServerStorage.House4, [5] = game.ServerStorage.House5, [6] = game.ServerStorage.House6, [7] = game.ServerStorage.House7, [8] = game.ServerStorage.House8 } while true do wait(1) if game.Players:GetPlayers() == 1 then if game.Workspace.House1 then return else game.ServerStorage.House1:Clone(game.Workspace) end end end
I'm not really sure about this, but I don't see anywhere you have written where to place the houses, or that it should spawn a random house.
Try this:
game.Players.PlayerAdded:Connect(function) local AmountOfPlayers = #Players:GetPlayers() if workspace:FindFirstChild("House"..AmountOfPlayers) then print("House is allready spawned") else if game.ServerStorage:FindFirstChild("House"..AmountOfPlayers) then local house = game.ServerStorage::FindFirstChild("House"..AmountOfPlayers):Clone() house.Parent = workspace else warn("Not enough houses for ammount of players in server") end end
How this works? Whenever a player joins, it will check how many players there is currently. It will then check if that number of house is spawned. by doing workspace:FindFirstChild("House"..AmountOfPlayers) e.g if its 1 person. It wil be workspace:FindFirstChild("House1") If its not spawned, it will do the same function to find it in server storage and clone it into the map If its not in server storage, it will output a warning message into console telling you there is not enough houses.
This is a helpful link for detecting how many players is in a server