I asked this before and i thought i got it to work but it says it again...
i am trying to teleport 2 random people to a certain spot in the map (665.995,7.1,-115.005)
when i hit play it says
Workspace.Script:7: bad argument #1 to 'random' (interval is empty)
when i join the game with me and my friend in the same server it says
Workplace.Script:7: bad argument #1 to 'random' (interval is empty)
local allPlayers = {} for a,v in pairs(game.Players:GetPlayers(2)) do table.insert(allPlayers,v) end local plrAmount = game.Players.NumPlayers math.randomseed(tick()) local val1 = math.random(plrAmount) local val2 repeat wait(5) val2 = math.random(plrAmount) until val2 ~=val1 allPlayers[val1].Character.Torso.CFrame = CFrame.new(0,0,0) allplayers[val2].Character.Torso.CFrame = CFrame.new(665.995,7.1,-115.005)
math.random
takes two parameters, the starting integer and the ending integer. You only have given the ending integer, which is the total amount of players in the game.
You want to search through all the players in the game, so your starting integer would be one. This means it gets the entire table of players from the beginning of the table to the end of the table.
local allPlayers = {} for a,v in pairs(game.Players:GetPlayers()) do table.insert(allPlayers,v) end local plrAmount = game.Players.NumPlayers math.randomseed(tick()) local val1 = math.random(1, plrAmount) --1 is the starting integer while plrAmount is the ending integer local val2 repeat wait(5) val2 = math.random(1, plrAmount) --1 is the starting integer whiel plrAmount is the ending integer until val2 ~=val1 allPlayers[val1].Character.Torso.CFrame = CFrame.new(0,0,0) allplayers[val2].Character.Torso.CFrame = CFrame.new(665.995,7.1,-115.005)
Here is information on math.random and what you did wrong.
If I helped you out, be sure to accept my answer!