Hello, I am currently having trouble on inserting a value. Every time I do it, it gives me an error. If you know anything about this error or what it means and how I can possibly fix it, please let me know. Thanks! (And also, if you need any more information, I'd be glad to get you what you need.)
Error:
Workspace.GameScripts.Maps.FoggyRailroad:102: attempt to index upvalue 'table' (a nil value)
Workspace.GameScripts.Maps.FoggyRailroad scripts:
local table spikestween = {
[1] = tweenspike1,
[2] = tweenspike2,
[3] = tweenspike3,
[4] = tweenspike4,
[5] = tweenspike5,
[6] = tweenspike6,
[7] = tweenspike7,
[8] = tweenspike8,
[9] = tweenspike9,
[10] = tweenspike10,
[11] = tweenspike11,
[12] = tweenspike12,
}
local table avoidings = {
[1] = "Train",
[2] = "Zombies",
[3] = "Spikes",
[4] = "Brawl",
[5] = "Bombs",
[6] = "Lightning",
[7] = "Tag",
[8] = "Coin Multiplier",
[9] = "Disco Players",
[10] = "Gravity Coil",
[11] = "Speed Coil",
[12] = "Rocket Brawl",
[13] = "Bomb Brawl",
[14] = "Character Jam",
[15] = "Murderer"
}
local table alreadyused = {} -- THIS IS THE TABLE USED
local avoiding = nil
game.ReplicatedStorage.CurrentMap.Changed:Connect(function()
if rs.CurrentMap.Value == "Foggy Railroad" then
rs.Foggy_Railroad.AvoidAdded:Fire("Trains")
repeat
avoiding = avoidings[5]
if avoiding == "Zombies" then
table.insert(alreadyused, "Zombies")
for i = 5, 0, -1 do
local clone = game.ServerStorage.Zombie:Clone()
gfunction.teleportAnything(clone, game.Workspace.Railroad_Spawn)
clone.Parent = workspace
end
else if avoiding == "Spikes" then
table.insert(alreadyused, "Spikes")
for i = 12, 1, -1 do
spikestween[i]:Play()
end
else if avoiding == "Brawl" then
table.insert(alreadyused, "Brawl")
for i,p in ipairs(game.Players:GetPlayers()) do
gfunction.giveGear(p, game.ServerStorage.ClassicSword)
end
else if avoiding == "Bombs" then
table.insert(alreadyused, "Bombs") -- THIS IS THE LINE THAT GOT THE ERROR
rs.Foggy_Railroad.AvoidAdded:Fire("Bombs")
else if avoiding == "Lightning" then
table.insert(alreadyused, "Lightning")
rs.Foggy_Railroad.AvoidAdded:Fire("Lightning")
else if avoiding == "Tag" then
table.insert(alreadyused, "Tag")
-- Do Later
else if avoiding == "Coin Multiplier" then
table.insert(alreadyused, "Coin Multiplier")
else if avoiding == "Disco Players" then
table.insert(alreadyused, "Disco Players")
rs.Foggy_Railroad.AvoidAdded:Fire("Disco Players")
else if avoiding == "Gravity Coil" then
table.insert(alreadyused, "Gravity Coil")
for i,p in ipairs(game.Players:GetPlayers()) do
gfunction.giveGear(p, game.ServerStorage.GravityCoil)
end
else if avoiding == "Speed Coil" then
table.insert(alreadyused, "Speed Coil")
for i,p in ipairs(game.Players:GetPlayers()) do
gfunction.giveGear(p, game.ServerStorage.SpeedCoil)
end
else if avoiding == "Rocket Brawl" then
table.insert(alreadyused, "Rocket Brawl")
for i,p in ipairs(game.Players:GetPlayers()) do
gfunction.giveGear(p, game.ServerStorage.RocketLauncher)
end
else if avoiding == "Bomb Brawl" then
table.insert(alreadyused, "Bomb Brawl")
for i,p in ipairs(game.Players:GetPlayers()) do
gfunction.giveGear(p, game.ServerStorage.Bomb)
end
else if avoiding == "Character Jam" then
table.insert(alreadyused, "Character Jam")
rs.Foggy_Railroad.AvoidAdded:Fire("Character Jam")
else if avoiding == "Murderer" then
local randomplayer = game.Players:GetPlayers()[math.random(1,#game.Players:GetPlayers())]
gfunction.giveGear(randomplayer, game.ServerStorage.Handgun)
end
end
end
end
end
end
end
end
end
end
end
end
end
end
wait(15)
until game.ReplicatedStorage.CurrentMap ~= "Foggy Railroad"
end
end)

8 comments
First of all, variables are lexical(I think that's what you call it). This means that the variable's type is from its value.Thus, making it so you don't need to type in i.e local int myVar = 5 (You also don't have to type in constant,static etc.). You don't need to make a new dictionary as a number. You can do tbl[index]. Third of all, you should be using elseif instead of else if to decr
I am extremely confused. I don't know how that is suppose to help the issue I'm having.
The variables part say what is incorrect about the code. Since you have a space in your variable name, it makes that variable nil.
That isn't a space, "alreadyused" is the variable name. table is the variable type. I don't know if that has to do anything with the error though.
I would like to chat with you in the scripting helpers chat and help you :)
How do I get there? I am kind of a new guy to scripting helpers.
@ZenerFox, I said that you don't need to specify the type of the variable in Lua. What is actually happening is that it will get the variable's value, and from that, it will say its type
@ZenerFox see a bar saying, "Community Chat"?