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

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
0
What Line is the error in? woodengop 1134 — 9y
0
Continent, the error recorded is in line 31, but it can happen in any line thats has nameType, and I don't know why. (the error i recorded is ServerScriptService.Game:31: attempt to index global 'typeName' (a nil value) PurpleTerror 10 — 9y
0
Thats it it you're missing Parenthesis should be "TypeName"! woodengop 1134 — 9y

4 answers

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

There is a ton of repetitive code here, so here is your code reduced using a for loop:

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()
    for ROUND = 1, 5 do
        print (#type)
        typeName = type[math.random(1, #type)]
        typeName = game.ServerStorage.enemies:FindFirstChild(typeName)
        typeClone = typeName:Clone()    
        game.Workspace.Lobby:Play()
        for i = (ROUND == 1 and 60 or 15), 1, -1 do
            status.Value = "Round " .. ROUND .. "/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)
    end
    mapClone:Destroy()
end

To address your actual issue, the only problem I can see here is that the chosen typeName is not actually in ServerStorage.enemies.

Can you take a screenshot of the Explorer pane, with all the children of ServerStorage.enemies visible?

0
It's erroring on 'Shoop Da Whoop'. In the game, you've spelt it without an 'h', but in the script, you spelt it *with* and 'h'. adark 5487 — 9y
0
Oh!! I'm such a dumbo sometimes. PurpleTerror 10 — 9y
Ad
Log in to vote
0
Answered by
woodengop 1134 Moderation Voter
9 years ago

You're missing Parenthesis. Like in line 30 should be

typeName = game.ServerStorage.enemies:FindFirstChild("typeName")

I pretty sure thats your problem.

If this was helpful please Upvote **and **Accept answer!

0
Why is this a Downvote? woodengop 1134 — 9y
0
He has parenthesis and you don't put quotes around a variable name... (I did not down-vote you but I can see why you were) VariadicFunction 335 — 9y
Log in to vote
-1
Answered by 9 years ago

I did Dewn's solution, it came up with 'attempt to index global 'dsastrName' (a nil value)' after a few rounds

0
Did you spell that incorrectly? Because you never use that variable... VariadicFunction 335 — 9y
0
Please don't submit an answer to add a comment to your question. Either edit the question or post an actual comment. adark 5487 — 9y
Log in to vote
-2
Answered by 9 years ago

type is a Lua keyword, change the variable name. If that doesn't work tell me.

0
It Depends, Unless you add another Word or letter to it, like true=true BAD/truey=true GOOD, So that wouldn't bother. woodengop 1134 — 9y
0
`type` is actually *not* a Lua keyword, it's just a built-in function. You can overwrite it no problems, although that makes it impossible to actually use the `type` function. adark 5487 — 9y

Answer this question