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

I know its deprecated, but how do I replace it?

Asked by 6 years ago

Hello! I am creating a game that when event happens, then 2 random players get teleported to the place so that they can action. I placed in the basics here, don't mind any other things beside the spawn stuff. When I use the normal "Play" button, my player teleports, and I get my thing. But why the heck when I use the Local Server test with 3 players does the error message say:

"22:49:54.275 - ServerScriptService.MainScript:6: bad argument #2 to 'random' (interval is empty) 22:49:54.277 - Stack Begin 22:49:54.279 - Script 'ServerScriptService.MainScript', Line 6 - local spawnplr1 22:49:54.281 - Script 'ServerScriptService.MainScript', Line 34 22:49:54.282 - Stack End"

I am usually good with this stuff but I am completely confused. I know it has something to do with the math.random function... but I can't seem to get the concept on WHY its giving me this message. Please help. Thanks!

(I didn't want to give my game TO MUCH info, so I used the **.)

local sword = game.ServerStorage.ClassicSword
local spawn1 = game.Workspace.BoxingMap.BoxingMap.BoxingRing.Team1SpawnPart
local spawn2 = game.Workspace.BoxingMap.BoxingMap.BoxingRing.Team2SpawnPart

local function spawnplr1()
    local plr1 = game.Players:GetPlayers()[math.random(1, game.Players.NumPlayers)].Character:FindFirstChild("HumanoidRootPart")
    plr1n = plr1.Parent.Name
    print(plr1n.." is player 1")
    if plr1 then
        plr1.CFrame = spawn1.CFrame + Vector3.new(0,5,0)
        sword:Clone().Parent = plr1.Parent
    end
end


local function spawnplr2()
    local plr2 = game.Players:GetPlayers()[math.random(1, game.Players.NumPlayers)].Character:FindFirstChild("HumanoidRootPart")
    local plr2n = plr2.Parent.Name
    if not plr2n == plr1n then
        print(plr2n.." is player 2")
        if plr2 then
            plr2.CFrame = spawn1.CFrame + Vector3.new(0,5,0)
            sword:Clone().Parent = plr2.Parent
        end
    end
end

local function runround()

end

while true do
    wait(5)
    spawnplr1()
    spawnplr2()
    runround()
end

1 answer

Log in to vote
0
Answered by 6 years ago

NumPlayers is 0 when server starts

math.random(1,0)
--> invalid
0
Oh, alright. Thanks for the information! :) ScrappyFriend77 34 — 6y
Ad

Answer this question