Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

I dont understand this error: bad argument #2 (interval is empty) Can someone help?

Asked by
bx3t 2
4 years ago
Edited 4 years ago


local plrs = game.Teams.lobby:GetPlayers() player = math.random(1,#plrs) print(player.Name)

2 answers

Log in to vote
2
Answered by 4 years ago
Edited 4 years ago

The error is telling you that there are no values inside of the plrs table. I believe this is because players are added during runtime while this script checks instantly (I'm assuming this is the only thing in your script). In order to fix this, you could either wait until a player joins by using a PlayerAdded event inside of a Server Script, or you could just wait for the character using a Local Script.

Server Script

game.Players.PlayerAdded:Connect(function(plr)
    local plrs = game.Teams.lobby:GetPlayers()
    local randomPlayer = plrs[math.random(1, #plrs)] 
    print(randomPlayer.Name)
end

Local Script

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait() --waits until the localplayer's character is loaded which is enough time for the player to join the team
local plrs = game.Teams.lobby:GetPlayers()
local randomPlayer = plrs[math.random(1, #plrs)] 
print(randomPlayer.Name)
0
Thanks! It 100% works! bx3t 2 — 4y
0
No problem! Please upvote and mark this question as the answer :) Godlydeathdragon 227 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

First of all, try using the following format when writing code (it just clears things up a bit);

print("See, this is how code should be formatted on this site.")

Next, we are going to need quite a bit more information than you've given us. What are you trying to accomplish here? What is the result you hope for, and is anything happening other than that error? Please reply with more information (and maybe proper formatting) if you want an answer.

Answer this question