Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Attempt to index local 'Staff' A nil Value?

local Debounce = true
script.Parent.Touched:connect(function(Handle)
	

local Number = Handle:FindFirstChild("CardNumber")

local Staff = Handle:FindFirstChild("BoolValue")
if Staff.Value then



if Debounce == true then
	Debounce = false

if Staff.Value == true
		then 
		script.Parent.Parent.Door.Transparency = 0.4
		script.Parent.Parent.Door.CanCollide = false
		wait(2)
		script.Parent.Parent.Door.Transparency = 0
		script.Parent.Parent.Door.CanCollide = true
	
else
	if Number then
	script.Parent.RoomNumber.Value == Number.Value and Staff.Value == false
		then 
		script.Parent.Parent.Door.Transparency = 0.4
		script.Parent.Parent.Door.CanCollide = false
		wait(2)
		script.Parent.Parent.Door.Transparency = 0
		script.Parent.Parent.Door.CanCollide = true
	else
		print("Incorrect card")
	end
end

wait(0.3)
elseif Debounce == false then
	Debounce = true
end


end)

19:18:43.033 - Workspace.Functional Door Kitorari.Scanner.Script:9: attempt to index local 'Staff' (a nil value)

^I'm not sure whats going on. The Boolvalue is there. And CardNumber isn't having problems...

How do I fix this?

Help would be great..

3 answers

Staff is a NumberValue object, you say? Then why are you looking for an object with name "BoolValue"?

My guess is Handle.BoolValue does not exist. For this reason, Staff gets assigned the value nil and indexing a nil value through the . or [ ] operators cause an error.

1 comment

0

Actually, I meant BoolValue. Sorry. XD

#What you did wrong? You forgot to complete the if then statement. You need the then at the end in order to actually run the code you need the then.


#Final Product

script.Parent.Touched:connect(function(Handle)

local Number = Handle:FindFirstChild("CardNumber")

local Staff = Handle:FindFirstChild("BoolValue") --Staff should be a boolvalue. Not a number value named "BoolValue"
if Debounce then --If debounce then is the same as if debounce == true then.
    Debounce = false
if Staff.Value then --This is because the statement is only checking for a true value.
--If debounce is true then you don't need an operator to make it true.


Hope it helps!

1 comment

0

Actually, That didn't work. Lemme post the whole script..

local Debounce = true


script.Parent.Touched:connect(function(Handle)


local Number = Handle:WaitForChild'CardNumber' --Possibly Handle.Parent:WaitForChild'CardNumber'

local Staff = Handle:WaitForChild'BoolValue' -- Possibly Handle.Parent:WaitForChild'BoolValue'


if Staff.Value and Debounce then
	script.Parent.Parent.Door.Transparency = 0.4
	script.Parent.Parent.Door.CanCollide = false
	wait(2)
	script.Parent.Parent.Door.Transparency = 0
	script.Parent.Parent.Door.CanCollide = true
else
	if script.Parent.RoomNumber.Value == Number.Value and not Staff.Value then
		script.Parent.Parent.Door.Transparency = 0.4
		script.Parent.Parent.Door.CanCollide = false
		wait(2)
		script.Parent.Parent.Door.Transparency = 0
		script.Parent.Parent.Door.CanCollide = true
	else 
		print'Incorrect Card!'
end end end)


Why did you use '' instead of ("")!? I use '' for simply the ease of quicker typing, I'll only use the quotes with brackets if I do stuff like.

game.Workspace:FindFirstChild(game.Workspace.Part) -- This kind of stuff... But not as stupid.

Why aren't there any == true or == false's This is a good habit to start with true's and false's. Always try to shorten your script by doing.

if game.Workspace then
print'Done'
end -- This would be the same if I were to do if game.Workspace == true then

If you have any other questions, just ask!

1 comment

0

Omitting parentheses in a function call is a personal choice. But because you can do it doesn't mean you should.

This discussion is preserved as it was. New answers, comments, and votes are closed.