Got help from very helpful dudes, and this is what left that they could not figure out:
The error that is getting spit out is - 8: bad argument #1 to 'random' (interval is empty)
TeamName = "Monster" players = game.Players:GetPlayers() selected = "" function SelectPlayer() if #players ~= 1 then print(#players) local num = math.random(game.Players.NumPlayers) selected = players[num] else selected = players[1] end end SelectPlayer() function TeamPlayer(player) local play = game.Players:FindFirstChild(player.Name) local team = game.Teams:FindFirstChild(TeamName) if play~= nil then play.TeamColor = team.TeamColor end end TeamPlayer(selected)
Please don't say "Nobody can find the solution" when 2 people told you the solution on your previous post
Your script obviously will not work without a player, I setup a minimum amount because it's not useful at all to pick a "random player" with only one player in the game
local minimum = 3 -- The minimum amount of players needed to start a game local playerServ = game:GetService("Players") while #playerServ:GetPlayers() < minimum do wait(0.5) end local function SelectPlayer() local players = playerServ:GetPlayers() if #players < minimum then return end local random = players[Random.new():NextInteger(1, #players)] random.Team = game.Teams.someTeam end SelectPlayer()
function SelectPlayer() if #players ~= 1 then print(#players) math.randomseed(math.random(tick())) local num = math.random(1, #game.Players:GetPlayers()) selected = players[num] else selected = players[1] end end
Marked as Duplicate by Vulkarin, UgOsMiLy, TheeDeathCaster, Goulstem, cabbler, and lukeb50
This question has been asked before, and already has an answer. If those answers do not fully address your question, then please ask a new question here.
Why was this question closed?