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

ServerScriptService.mini game script:18: attempt to index nil with 'GetChildren'?

Asked by 2 years ago

I changed line 18 from local players = game.Players to local players = Region3.Players and now im getting a ServerScriptService.mini game script:18: attempt to index nil with 'GetChildren' error

local status = game.ReplicatedStorage.status
local maps = game.ReplicatedStorage.maps:GetChildren()
while true do
    for i = 1,3
    do
        status.Value = "Intermisson:"..3-i
        wait(1)
    end

    local rand = math.random(1, #maps)

    local map = maps [rand]:Clone()
    map.Parent = workspace

    status.Value = "we'll be playing "..map.Name
    wait(3)

    local players = Region3.Players:GetChildren()
    for i = 1,#players do
        if players[i].Character ~= nil then
            local spawnlocation = math.random(1,#workspace.Teleports:GetChildren())
            players[i].Character:MoveTo(workspace.Teleports:GetChildren()[spawnlocation].Position)
            players[i].Character.Parent = workspace.ingame
        end
    end

    local roundlength = 50

    local canwin = true

    if map:FindFirstChild("obby") then
        map.endpart.Touched:Connect(function(hit)
            if hit.Parent:FindFirstChild("Humanoid")then
                canwin = true
                status.value = hit.Parent.name.."he's won"
            end
        end)
    end

    repeat
        roundlength = roundlength -1
        status.Value =  "time left:"..roundlength
        wait(1)
    until roundlength == 0 or canwin == false or #workspace.ingame:GetChildren()==0

    wait(1)
    map: destroy()

    local players = game.Players:GetChildren()
    for i = 1, #players do
        if players[i].Character ~= nil then
            players[i]:LoadCharacter()
        end
        end
    end

1 answer

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

There are no Region3's defined in this code, and either way, "Players" is not a valid property of a Region3. It looks like you're just teleporting people, so you can just use

local players = game.Players:GetPlayers()

as a sidenote, instead of doing this to loop through a table:

local table = {"a", "b", "c"}
for i = 1, #table do
    print(table[i])
end

you can do this:

local table = {"a", "b", "c"}
for i, value in pairs(table) do
    print(value)
end
Ad

Answer this question