Boolean Skill Issue?

Hey everyone. I’m having an issue with a reference to a boolean. It seems to change to thinking its a variable inside the script instead of a reference, giving me the error “Attempt to index boolean with ‘Value’” on line 30. For some reason it errors in an if statement, and it runs one time before throwing the error for subsequent runs.

I searched up the error on here, but came up empty-handed for answers.

Here’s what I got.

if isOpen.Value == false then -- Error here.
	animUnlocked:Play()
	task.wait(2.4)
	isOpen.Value = true
else
	animUnlocked:AdjustSpeed(1)
	task.wait(2.4)
	isOpen.Value = false
end

How are you referencing isOpen?

According to the error, you may be referencing it as such:
local isOn = PATH_TO_IS_ON.Value

Precisely, yeah.

prompt = script.Parent -- ProximityPrompt
isOpen = prompt.IsOpen

Are you sure you’re not re-defining it somewhere after?
Like I said, if you print isOpen right before the line that errors, you will likely see that it is a boolean value.

I am indeed redefining it apparently, however I can’t see how. The code I sent above is the end of the script pretty much.
Here’s the entire function.

prompt.Triggered:Connect(function()
	prompt.Enabled = false
	if isLocked.Value == false then
		print(isOpen)
		if isOpen.Value == false then
			animUnlocked:Play()
			task.wait(2.4)
			isOpen.Value = true
		else
			animUnlocked:AdjustSpeed(1)
			task.wait(2.4)
			isOpen.Value = false
		end
	else
		print("locked")
	end
	prompt.Enabled = true
end)

I can’t really provide a solution or any help unless you’re able to send the full script. From the snippets you’ve sent, it looks fine, but I can’t be sure since there might be other code in between.

Here is the entire script.

prompt = script.Parent
isLocked = prompt.IsLocked
isOpen = prompt.IsOpen
interact = prompt.Parent
doorClose = interact.Close
doorLocked = interact.HandleLocked
doorUnlocked = interact.HandleUnlocked
door = interact.Parent
controller = door.AnimationController
animator = controller.Animator
animUnlocked = animator:LoadAnimation(animator.Parent.Unlocked)
--animLocked = animator:LoadAnimation(animator.Parent.Locked)

animUnlocked:GetMarkerReachedSignal("PlayKnobSFX"):Connect(function()
	doorUnlocked:Play()
end)

animUnlocked:GetMarkerReachedSignal("Stop"):Connect(function()
	animUnlocked:AdjustSpeed(0)
	isOpen = true
end)

animUnlocked:GetMarkerReachedSignal("CloseSound"):Connect(function()
	doorClose:Play()
end)

prompt.Triggered:Connect(function()
	prompt.Enabled = false
	if isLocked.Value == false then
		print(isOpen)
		if isOpen.Value == false then
			print(isOpen)
			animUnlocked:Play()
			task.wait(2.4)
			isOpen.Value = true
			print(isOpen)
		else
			animUnlocked:AdjustSpeed(1)
			task.wait(2.4)
			isOpen.Value = false
			print(isOpen)
		end
	else
		print("locked")
	end
	prompt.Enabled = true
end)

I printed isOpen after every point where I set the variable to see where it redefines, and it only does after the script finishes. Maybe if i set it to a local reference inside the function, then it will work?

Ah there, inside animUnlocked:GetMarkerReachedSignal("Stop"), you are setting isOpen to a boolean directly. Change that to isOpen.Value = true.

Oh my god i completely forgot about that…
I was adding the .value because I had forgotten to do so originally, and missed that.

1 Like

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