I get this error on my main game script: 17:36:39.401 - ServerScriptService.MainGameScript:26: bad argument #2 to 'random' (interval is empty)
This is line 26: d1 = players[math.random(1, #players)]
Yes, players is defined. Please help? Confused. Also, I know that the second argument cannot be lower than the first one, but the second argument is always wrong even if the table is reading it, let's say 1-3.
Make sure you're using the typical events to detect players being added to your game, before calling this - otherwise you won't get the correct results.
game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) -- Your code goes here local players = game.Players:GetPlayers() --[[ this is for test only , but you would put the code below in a function that picks the random player before starting a new round --]] d1 = players[math.random(1, #players)] end) end)
Please make sure players is defined as such:
local players = game.Players:GetPlayers()