Button system: attempt to index local 'currentbutton' (a nil value)

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
2 Likes

May I see the Explorer tab and Properties tab of the OnButton?

I can’t take a picture of it so I am just going to explain. There is a script in ServerScriptService called, ā€œButtonsā€ and inside ā€˜Buttons’ there is a NumberValue called, ā€œOnButtonā€.

Are you on windows 10? If so just take a photo with snipping tool.

Okay. How do I do it though? I don’t know how

Hover on the bottom of your screen with your mouse. Then in the search tab search snipping tool then click on snipping tool.

What is the value of the NumberValue before you run the script?

The starter value (or the value that we first started) is 1.

Annotation 2020-01-12 174807

Do you have a value in the OnButton value? If you are trying to get the value of it do *
local currentbutton = script.OnButton.Value.

Have you tried removing the variable for the currentbutton on this function? It may be messing with the variable defined at the top of the script. Just trying to eliminate possible sources.

1 Like

Annotation 2020-01-12 175125

And define the variable in the function.

I have to use local currentbutton = script.OnButton cause on the other lines it says, ā€œcurrentbutton.Valueā€

So I think it did work but I ended up with a new problem…

ServerScriptService.Buttons:24: attempt to concatenate local 'c' (a userdata value)

Which line is line 24? It’s hard to find it on the website.

local button = m.Buttons:FindFirstChild("Button_"..c)

And is that variable coming from a Local Script via a ServerEvent?

It is coming from the inside of the server script.

@xZylter, I fixed my script a little, and when I pressed the first button, it turned red (good) and the other button turned green (good) but when I pressed any other buttons, it didn’t do anything and the output didn’t send anything. Here is the current script:

Edit: The Interactives didn’t do anything.