Attempt to index boolean with "Value"

  1. What do you want to achieve? I’m making a block move for my fighting game!

  2. What is the issue? on line 53, the output gives me a error describing the line: Attempt to index boolean with “Value”

  3. What solutions have you tried so far? I tried searching the forums but to no avail.

Here’s the code:

elseif Input.KeyCode == Enum.KeyCode.B then --B Button Pressed!
    BlockTrack:Play()
    WalkSpeed = 0
    JumpPower = 0
    BlockCheck.Value = true -- This gives me the error
end

Are there any mistakes I’ve put? Please do reply!

9 Likes

I’m pretty sure you’re trying to set a Value inside a Sound to be true right? I think you’d have to write BlockCheck.Value.Value I might be on the wrong track though.

The error you get means that the “BlockCheck” variable doesn’t have .Value. Try removing that and make the line this: BlockCheck = true

You’ve probably confused two concepts somewhere along the way of a BoolValue object vs a boolean type.

BoolValue is an object you can insert in the explorer. It has a property named “Value”, which can either be true or false.

In Lua, you can have a variable contain a reference to that BoolValue object, and access its Value property which will give you true or false.

However, you can also just store a boolean value directly in a variable. Here’s an example of each

BoolValue object:
local boolReference = workspace.MyBoolValue
To set its value:
boolReference.Value = true
To retrieve its value later,
print(boolReference.Value) > output: true

boolean variable:
local myBool = true
To set its value:
myBool = false
To retrieve its value later,
print(myBool) > output: false

So, what is causing your error?
Check if your variable contains a reference to a BoolValue object or if it is storing a boolean directly.
If it is supposed to contain a reference to a BoolValue, then look for somewhere else in your code where you accidentally set it directly to a boolean value.

If it is supposed to contain a bool value and not a reference to a BoolValue object, then just get rid of the .Value on the erroring line and you should be all set.

15 Likes