Why i am getting this error

When I touch the button I am getting this error saying ServerScriptService.Script:11: attempt to index nil with ‘Value’ .

Here is my code for when you touch the button

local mainGame = game.Workspace:WaitForChild("MainGame") 

local gates = mainGame:WaitForChild("Gates") -- gets the gates
local buttons = mainGame:WaitForChild("Buttons") -- gets the buttons

local function activateButton(button,touched) -- function to activate the button
	touched.Value = true
	local gate = gates:FindFirstChild(buttons.Name) -- finds child gate
	
	local duration = buttons:FindFirstChild("Duration") -- finds child duration
	
	local timer = duration.Value -- error here
	while timer > 0 do -- timer program
		
		print(timer)
		task.wait(1)
		timer = timer - 1
	end
	
	if gate then -- when child gate has been found
		gate.Transparency = 0.5
		gate.CanColide = true
		print("hi")

	end
	
	
	
	--task.wait(duration.Value)
	
	
	
	
	
end


for  _, button in pairs(buttons:GetChildren()) do -- a loop to get the chlidren of the buttons
	button.Touched:Connect(function(otherpart)
		local humanoid = otherpart.Parent:FindFirstChild("Humanoid") -- finds child humanoid
		local touched = button:FindFirstChild("Touched") -- finds child touched
		
		if humanoid and touched and touched.Value == false then -- activates the button if false
			activateButton(button,touched)
		end
	end)
end

is the Duration variable a NumberValue Or an IntegerValue.
it should not error if it has a property called value; unless if there is another instance named “Duration”

what is the diffrence from a number value and a interger value

an intvalue or integer value is a value that can hold integers which means it can hold numbers that are not decimals

The vairable duration is a integer value

So do you think anything is wrong with the script?

There might be something wrong with the touched parameter what value is that argument.

If you read the error and take it at face value it’s saying that you’re doing the following:

local duration = nil -- FFC returns nil
local timer = duration.Value -- attempt to index nil.Value

This is where things get messy, if you’re doing FindFirstChild calls and not explicitly checking their returns, you’re masking where the error is.

I assume you want local duration = button:FindFirstChild("Duration") Notice it’s not button[s].

1 Like

Can you show the explorer window of the “Duration” value you are trying to call?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.