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

My game script plays a few rounds, suddenly errors, and stops?

Asked by 9 years ago

Hi, this is an irritating error. I finished my gamescript, plays all rounds and stuff. However, after a couple of rounds, it errors with this:

"ServerScriptService.Game:31: attempt to index global 'typeName' (a nil value)"

And the script stop working.

I have no idea how to fix this, its driving me crazy!!

status = game.ServerScriptService.Status
local type = {"Meteor Shower","Raining Noobs","Moon","Eerie Darkseed","Tsunami","Master Hand","Acid Rain","Deadly Egg Rain","Rising Lava","Epic Duck","Raining Knives","Shoop Da Whoop"}
sfx = {}
map = {}
leaderboard = nil
local w = game.Workspace:getChildren()
for i=1,#w do
    if w[i].Name == "leaderboard" and w[i]:findFirstChild("running") ~= nil and w[i]:findFirstChild("points") ~= nil then
        leaderboard = w[i]
    end
end

for i,game in pairs (game.ServerStorage:FindFirstChild("Maps"):GetChildren()) do
    table.insert(map,#map+1,game.Name)
end

for i,game in pairs (game.ServerStorage:FindFirstChild("SoundTrack"):GetChildren()) do
    table.insert(sfx,#sfx+1,game.Name)
end

while true do
    print(#map)
    mapName = map[math.random(1, #map)]
    mapName = game.ServerStorage.Maps:FindFirstChild(mapName)
    mapClone = mapName:Clone()
    mapClone.Parent = game.Workspace
    mapClone:MakeJoints()
    print (#type)
    typeName = type[math.random(1, #type)]
    typeName = game.ServerStorage.enemies:FindFirstChild(typeName)
    typeClone = typeName:Clone()    
    game.Workspace.Lobby:Play()
    for i = 60, 1, -1 do
        status.Value = "Round 1/5 will start in: "..i
        wait(1)
    end
    game.Workspace.Lobby:stop()
    status.Value = "Disaster: "..typeClone.Name
    wait(3) 
    sfxName = sfx[math.random(1, #sfx)]
    sfxName = game.ServerStorage.SoundTrack:FindFirstChild(sfxName)
    sfxClone = sfxName:Clone()  
    sfxClone.Parent = game.Workspace
    sfxClone:play()
    workspace.points.Value = 20
    game.Workspace.running.Value = true
    typeClone.Parent = game.Workspace
    typeClone:MakeJoints()
    for i = 30, 1, -1 do
        status.Value = "Time until round ends: "..i
        wait(1)
    end
    typeClone:remove()
    sfxClone:Stop()
    sfxClone:destroy()      
    game.Workspace.running.Value = false
    status.Value = "Results!"
    wait(5)
    print (#type)
    typeName = type[math.random(1, #type)]
    typeName = game.ServerStorage.enemies:FindFirstChild(typeName)
    typeClone = typeName:Clone()    
    game.Workspace.Lobby:Play()
    for i = 15, 1, -1 do
        status.Value = "Round 2/5 will start in: "..i
        wait(1)
    end
    game.Workspace.Lobby:stop()
    status.Value = "Disaster: "..typeClone.Name
    wait(3) 
    sfxName = sfx[math.random(1, #sfx)]
    sfxName = game.ServerStorage.SoundTrack:FindFirstChild(sfxName)
    sfxClone = sfxName:Clone()  
    sfxClone.Parent = game.Workspace
    sfxClone:play()
    workspace.points.Value = 20
    game.Workspace.running.Value = true
    typeClone.Parent = game.Workspace
    typeClone:MakeJoints()
    for i = 30, 1, -1 do
        status.Value = "Time until round ends: "..i
        wait(1)
    end
    typeClone:remove()
    sfxClone:Stop()
    sfxClone:destroy()      
    game.Workspace.running.Value = false
    status.Value = "Results!"
    wait(5)
    print (#type)
    typeName = type[math.random(1, #type)]
    typeName = game.ServerStorage.enemies:FindFirstChild(typeName)
    typeClone = typeName:Clone()    
    game.Workspace.Lobby:Play()
    for i = 15, 1, -1 do
        status.Value = "Round 3/5 will start in: "..i
        wait(1)
    end
    game.Workspace.Lobby:stop()
    status.Value = "Disaster: "..typeClone.Name
    wait(3) 
    sfxName = sfx[math.random(1, #sfx)]
    sfxName = game.ServerStorage.SoundTrack:FindFirstChild(sfxName)
    sfxClone = sfxName:Clone()  
    sfxClone.Parent = game.Workspace
    sfxClone:play()
    workspace.points.Value = 20
    game.Workspace.running.Value = true
    typeClone.Parent = game.Workspace
    typeClone:MakeJoints()
    for i = 30, 1, -1 do
        status.Value = "Time until round ends: "..i
        wait(1)
    end
    typeClone:remove()
    sfxClone:Stop()
    sfxClone:destroy()      
    game.Workspace.running.Value = false
    status.Value = "Results!"
    wait(5)
    print (#type)
    typeName = type[math.random(1, #type)]
    typeName = game.ServerStorage.enemies:FindFirstChild(typeName)
    typeClone = typeName:Clone()    
    game.Workspace.Lobby:Play()
    for i = 15, 1, -1 do
        status.Value = "Round 4/5 will start in: "..i
        wait(1)
    end
    game.Workspace.Lobby:stop()
    status.Value = "Disaster: "..typeClone.Name
    wait(3) 
    sfxName = sfx[math.random(1, #sfx)]
    sfxName = game.ServerStorage.SoundTrack:FindFirstChild(sfxName)
    sfxClone = sfxName:Clone()  
    sfxClone.Parent = game.Workspace
    sfxClone:play()
    workspace.points.Value = 20
    game.Workspace.running.Value = true
    typeClone.Parent = game.Workspace
    typeClone:MakeJoints()
    for i = 30, 1, -1 do
        status.Value = "Time until round ends: "..i
        wait(1)
    end
    typeClone:remove()
    sfxClone:Stop()
    sfxClone:destroy()      
    game.Workspace.running.Value = false
    status.Value = "Results!"
    wait(5)
    print (#type)
    typeName = type[math.random(1, #type)]
    typeName = game.ServerStorage.enemies:FindFirstChild(typeName)
    typeClone = typeName:Clone()    
    game.Workspace.Lobby:Play()
    for i = 15, 1, -1 do
        status.Value = "Round 5/5 will start in: "..i
        wait(1)
    end
    game.Workspace.Lobby:stop()
    status.Value = "Disaster: "..typeClone.Name
    wait(3) 
    sfxName = sfx[math.random(1, #sfx)]
    sfxName = game.ServerStorage.SoundTrack:FindFirstChild(sfxName)
    sfxClone = sfxName:Clone()  
    sfxClone.Parent = game.Workspace
    sfxClone:play()
    workspace.points.Value = 20
    game.Workspace.running.Value = true
    typeClone.Parent = game.Workspace
    typeClone:MakeJoints()
    for i = 30, 1, -1 do
        status.Value = "Time until round ends: "..i
        wait(1)
    end
    typeClone:remove()
    sfxClone:Stop()
    sfxClone:destroy()      
    game.Workspace.running.Value = false
    status.Value = "Results!"
    wait(5)
    mapClone:Destroy()
end

Answer this question