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

Why am I getting 0 from this array?

Asked by
NRCme 0
8 years ago

Here is the code:

math.randomseed(tick())

local t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17,t18,t19,t20,t21,t22,t23,t24,t25,t26,t27,t28,t29,t30
CNP = 0
t = CNP
UIP = game.Workspace.UIP
local YourCNP
local rndm1 = math.random()
local rndm2 = math.random()
local rndm3 = math.random()
local rndm4 = math.random()
local UIP = workspace.UIP.Value

local rndm11 = math.ceil(rndm1*254)
local rndm22 = math.ceil(rndm2*254)
local rndm33 = math.ceil(rndm3*254)
local rndm44 = math.ceil(rndm4*254)

local StaticLocalIP = rndm11.. ".".. rndm22.. ".".. rndm33.. ".".. rndm44

game.Players.PlayerAdded:connect(function(player)
    print(player.Name.. " Has joined and is asigned the following IP: ".. StaticLocalIP)


    CNP = CNP + 1
    if t==1 then
        t1 = StaticLocalIP
    elseif t==2 then
        t2 = StaticLocalIP
    elseif t==3 then
        t3 = StaticLocalIP
    elseif t==4 then
        t4 = StaticLocalIP
    elseif t==5 then
        t5 = StaticLocalIP
    elseif t==6 then
        t6 = StaticLocalIP
    elseif t==7 then
        t7 = StaticLocalIP
    elseif t==8 then
        t8 = StaticLocalIP
    elseif t==9 then
        t9 = StaticLocalIP
    elseif t==10 then
        t10 = StaticLocalIP
    elseif t==11 then
        t11 = StaticLocalIP
    elseif t==12 then
        t12 = StaticLocalIP
    elseif t==13 then
        t13 = StaticLocalIP
    elseif t==14 then
        t14 = StaticLocalIP
    elseif t==15 then
        t15 = StaticLocalIP
    elseif t==16 then
        t16 = StaticLocalIP
    elseif t==17 then
        t17 = StaticLocalIP
    elseif t==18 then
        t18 = StaticLocalIP
    elseif t==19 then
        t19 = StaticLocalIP
    elseif t==20 then
        t20 = StaticLocalIP
    elseif t==21 then
        t21 = StaticLocalIP
    elseif t==22 then
        t22 = StaticLocalIP
    elseif t==23 then
        t23 = StaticLocalIP
    elseif t==24 then
        t24 = StaticLocalIP
    elseif t==25 then
        t25 = StaticLocalIP
    elseif t==26 then
        t26 = StaticLocalIP
    elseif t==27 then
        t27 = StaticLocalIP
    elseif t==28 then
        t28 = StaticLocalIP
    elseif t==29 then
        t29 = StaticLocalIP
    elseif t==30 then
        t30 = StaticLocalIP
    end
    UIP = {t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17,t18,t19,t20,t21,t22,t23,t24,t25,t26,t27,t28,t29,t30}
    local tabl = {t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17,t18,t19,t20,t21,t22,t23,t24,t25,t26,t27,t28,t29,t30}
    YourCNP = CNP
    print(#tabl)
end)

game.Players.PlayerRemoving:connect(function(player)
    CNP = CNP - 1
end)

But it just prints 0 from the array, why?

1 answer

Log in to vote
0
Answered by
Pyrondon 2089 Game Jam Winner Moderation Voter Community Moderator
8 years ago

On lines 4 & 5, you set 't' to 'CNP', which is 0. 't' doesn't change anywhere else in the script. So, the if statement never assigns any of those values to anything, and nil doesn't count as a value in a table.

You're getting 0 as the length because it's an empty array.

0
But I set "t1" to the IP NRCme 0 — 8y
0
Ok never mind I get you! NRCme 0 — 8y
Ad

Answer this question