Ok so i made a map changer script but i cant figure out what the error is what i need to do he is the error 12:17:12.599 - Players.Player1.PlayerGui.InGameGui.Frame.TextBox.LocalScript:20: attempt to index local 'map' (a nil value)
while wait() do if script.Parent.Parent.Ended.Value == 1 then for i = 30,0, - 1 do local Text = script.Parent local Frame = script.Parent.Parent Text.Text = i wait(1) if i == 0 then script.Parent.Parent.Ended.Value = 0 spawnmap = game.Workspace.Spawnmap spawnmap.Value = 1 Text.Visible = false Frame.TextBox2.Text = "ROUND STARTING" wait(3) Text.Visible = false Frame.TextBox2.Text = "12 HOURS TELL DAY" local map = game.Workspace:FindFirstChild("Map"..spawnmap.Value) local target = map.thing.Position Players = game.Players:GetPlayers() local player = game.Players.LocalPlayer Num = Instance.new("IntValue",player) Num = math.random(1,#Players) if Num == 1 then player.PlayerGui.IngameGui.BackGround.Visible = true end if player.Shop.Value == 0 then player.Character:MoveTo(target) Min = 30 Sec1 = 0 Sec = 0 -- both should start at 0 Text.Text = Min..":"..Sec1..Sec for i = 600,0,-1 do wait(1) print(i) if i == 600 then Min = 9 Sec1 = 5 Sec = 9 Text.Text = Min..":"..Sec1..Sec elseif i == 540 then Min = 8 Sec1 = 5 Sec = 9 Text.Text = Min..":"..Sec1..Sec elseif i == 480 then Min = 7 Sec1 = 5 Sec = 9 Text.Text = Min..":"..Sec1..Sec elseif i == 420 then Min = 6 Sec1 = 5 Sec = 9 Text.Text = Min..":"..Sec1..Sec elseif i == 360 then Min = 5 Sec1 = 5 Sec = 9 Text.Text = Min..":"..Sec1..Sec elseif i == 300 then Min = 4 Sec1 = 5 Sec = 9 Text.Text = Min..":"..Sec1..Sec elseif i == 240 then Min = 3 Sec1 = 5 Sec = 9 Text.Text = Min..":"..Sec1..Sec elseif i == 180 then Min = 2 Sec1 = 5 Sec = 9 Text.Text = Min..":"..Sec1..Sec elseif i == 120 then Min = 1 Sec1 = 5 Sec = 9 Text.Text = Min..":"..Sec1..Sec elseif i == 60 then Min = 0 Sec1 = 5 Sec = 9 Text.Text = Min..":"..Sec1..Sec else Sec = Sec - 1 if Sec == -1 then Sec1 = Sec1 - 1 Sec = 9 end Text.Text = Min..":"..Sec1..Sec end end end Num:Destroy() end
When you see an error message attempt to index local 'map' (a nil value)
(where 'map' can be replaced by any variable name), this means that you have an unexpected nil value. That is, you're telling the script on line 20 to get "map.thing.Position", which requires that 'map' and 'map.thing' are both non-nil -- yet, the error is telling you, 'map' is nil. It is illegal to try and index a nil value (that is, attempt to do "nil.thing" or "nil.Value" or "nil.Anything"), hence the error.
So we go to the previous lines. Line 19 is where you try and assign 'map' a value. How might 'map' be nil there? If "workspace.Map1" does not exist (since 'spawnmap.Value = 1' as of line 13).
Some other problems with your script:
function example() randomCode() if condition then print("hi") elseif otherCondition then doSomething() else doSomethingElse() end for i = 1, 2 do for j = 100, 200 do print(i, j, i+j) end end end
for
loop using the same variable name you use on line 4. This hides the 'i' declared on line 4, meaning you cannot access it in your inner for
loop. You should use a different variable name (ex, j
) so that you access both for-loop variables.string.format
will suffice; the following bit replaces lines 34 to 98:for timeLeft = 599, 0, -1 do print(i) Text.Text = string.format("%d:d", math.floor(timeLeft / 60), timeLeft % 60) wait(1) end
Changes:
wait(1)
after the Text.Text so that the 0:00
part will display for a full second. Further, 9:59 will show up immediately rather than after a full second of waiting.