So I was making a flood escape 2 button type system and I came across this error:
attempt to index local 'currentbutton' (a nil value)
now, my script has allot. But only pay attention to the main lines.
local currentbutton = script.OnButton
local function fade(numb, map)
local interactive = map.Interactives:FindFirstChild("Interactive_"..numb)
interactive.Transparency = 1
interactive.CanCollide = false
end
local function appear(numb, map)
local interactive = map.Interactives:FindFirstChild("Interactive_"..numb)
interactive.Transparency = 0
interactive.CanCollide = true
end
local function unanchor(numb, map)
local interactive = map.Interactives:FindFirstChild("Interactive_"..numb)
interactive.Anchored = false
wait(map.Buttons:FindFirstChild("Button_"..numb)._Unanchor.Delay.Value)
interactive.Transparency = 1
interactive.CanCollide = false
end
local function check(c, m)
local button = m.Buttons:FindFirstChild("Button_"..c)
if button:FindFirstChild("_Fade") then
spawn(fade(c, m))
elseif button:FindFirstChild("_Appear") then
spawn(appear(c, m))
elseif button:FindFirstChild("_Unanchor") then
spawn(appear(c, m))
end
end
local function firstbuttontouched(Map, ButtonFolder, currentbutton)
local button = ButtonFolder:FindFirstChild("Button_1")
button.Light.BrickColor = BrickColor.new("Really red")
button.Light.TouchedE.Value = true
wait(0.1)
currentbutton.Value = currentbutton.Value + 1
wait(0.1)
local newbut = ButtonFolder:FindFirstChild("Button_"..currentbutton.Value)
button.Light.BrickColor = BrickColor.new("Lime green")
spawn(function()
check(currentbutton, Map)
end)
game.ReplicatedStorage.Bindables.InteractiveFunction:Invoke(currentbutton)
end
local function morebuttonstouched(Map, ButtonFolder, numb)
if ButtonFolder:FindFirstChild("Button_"..numb) then
local button = ButtonFolder:FindFirstChild("Button_"..numb)
button.Light.BrickColor = BrickColor.new("Really red")
button.Light.TouchedE.Value = true
wait(0.1)
currentbutton.Value = currentbutton.Value + 1
wait(0.1)
local newbut = ButtonFolder:FindFirstChild("Button_"..numb)
button.Light.BrickColor = BrickColor.new("Lime green")
spawn(function()
check(currentbutton, Map)
end)
game.ReplicatedStorage.Bindables.InteractiveFunction:Invoke(currentbutton)
elseif not ButtonFolder:FindFirstChild("Button_"..numb) then
print("We hit the spot!")
end
end
game.ReplicatedStorage.Bindables.ButtonFunction.OnInvoke = function(totalbuttons, Number, Map, ButtonFolder)
ButtonFolder:FindFirstChild("Button_"..currentbutton.Value).Hitbox.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if Map.StartButton.Value == false then
Map.StartButton.Value = true
spawn(function()
firstbuttontouched(Map, ButtonFolder)
end)
end
end
end)
end
game.ReplicatedStorage.Bindables.ButtonFunction2.OnInvoke = function(totalbuttons, Number, Map, ButtonFolder, numb)
ButtonFolder:FindFirstChild("Button_"..currentbutton.Value).Hitbox.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if Map.StartButton.Value == false then
Map.StartButton.Value = true
spawn(function()
morebuttonstouched(Map, ButtonFolder, currentbutton)
end)
end
end
end)
end
It would help if you responded!
Full error:
17:28:15.843 - ServerScriptService.Buttons:39: attempt to index local 'currentbutton' (a nil value)
17:28:15.872 - Stack Begin
17:28:15.873 - Script 'ServerScriptService.Buttons', Line 39 - upvalue firstbuttontouched
17:28:15.874 - Script 'ServerScriptService.Buttons', Line 74
17:28:15.874 - Stack End