Can't derive value from bool

Yo!
So I’m trying to make a rock that you can mine, and right now I’m having an issue with the tool I made for it. I have a BoolValue in the tool to indicate when the tool is ‘mining’ and for some reason, even though the script can see that the bool exists, and the function to change the value of the bool works, (In a different script) I can’t get the script within the tool to see the value of the bool. For example, I can do if mining then print("exists") (mining is the variable for the bool) then I get ‘exists’ in the output. However, if I do if mining.Value == true then print("It's true") I don’t get anything.

Here’s the script I have right now:

local mining = script.Parent.Mining
local debounce = script.Parent.Debounce
local hit = false

script.Parent.Handle.TouchPart.Touched:Connect(function(t)
	if t.Parent.Name == "Rock" then
		if mining.Value == true then
			print("Let's Mine!")
			t.Parent.Health.Value = t.Parent.Health.Value - 1
			mining.Value = false
		end	
	end
end)

mining.Changed:Connect(function()
	print("Change!")
end)

if mining then
	print("Bool Exists")
end

if mining.Value == true then
	print("Mining is true")
end

And here a picture of the hierarchy:
41%20PM
Mining is the script I sent.
Thanks!

1 Like

If the script is named Mining then you’d get the script instead of the bool. Try just changing the name of the script.

2 Likes

That didn’t work. Same thing happens.

1 Like

Are there any errors? On line 10 you’re not setting the value, so change that to mining.Value.

It is also good practice to use WaitForChild just in-case it hasn’t been created yet:

local mining = script.Parent:WaitForChild("Mining");
local debounce = script.Parent:WaitForChild("Debounce");
2 Likes

You could try this:

if mining and mining.Value then
    print ("mining is true")
end

or

print((mining and mining.Value) and "Mining is true" or "Mining is false")

Both check for the existence of the value and whether it’s true. The bottom one is just a shorter way to do it.

Kudos to @ScriptingSupport, as I learned how to use these “ternaries” from reading his posts!

1 Like

Did both things, still no change.

Oh and there are no errors*

Is the value of mining ever true? Where is it set to true? There must be more to the script.

1 Like

I’ve already found out that the script just can’t see the values existence. It can see the Instance, but not the value.

1 Like

From the look of it, the chunk of code:

is not under the changed function. So assuming that the boolean value is set to false before loading, of course it won’t print anything, and it’ll only get checked the first instance it loads.


The other problem is that you’re not changing the actual value of that boolean. You’re only setting the variable itself to be false.

It should instead be:

mining.Value = false
1 Like

There are other scripts, and the value does get set to true, and false. When I click it’s set to true, then after 0.75 seconds it’s false.

https://gyazo.com/f8ce98def887eefb301a5626fb77b68c

Does it set it to true on the client at any point? Print the ClassName of mining and make sure it is BoolValue.

1 Like

Yeah, it’s a bool value. Also the printing you see in the output is from another (server) script running this:

mining.Changed:Connect(function()
	if mining.Value == true then
		print("Mining_True")
	else
		print("Mining_False")
	end
end)

Are you absolutely sure there is no errors? What happens when you comment out the Touched event and just see if it prints “Change!” when you change the value.

1 Like

I commented out the entire function (line 5-13) and still got no ‘Change!’. And the only errors I get are from plugins. I have no idea what’s happening. I’m okay with offering a download of the place or maybe even a Team Create.

  1. The example I had was to demonstrate if I had that in the script, and I changed the bool to true nothing would happen.
  2. I fixed that.

If you could post a place file that’d be great. There isn’t much more I can say from this point without one.

Well in that case… what’s the default value of the mining boolean? If it’s already set to false, then setting it to false again won’t fire the changed function.

I’ve also noticed that there’s nothing setting it to true. It needs to be changed between the 2 to actually fire.

1 Like

It’s set to false by default, and it’s being changed from another script and I am sure that it’s changing the value.

Sure! Take a look.
Rock Place.rbxl (70.4 KB)
Ignore the button in the top left.

Is this other script perhaps a localScript? That’s the only problem I can think of since changes by a localScript can’t be seen via normal scripts.

1 Like