Why is my BoolValue not changing?

Why is my BoolValue not changing? I’m trying to change Attacking, which is child of script.Parent ( a tool ), but once checking, it turns out that Attacking.Value is not changing to false or true.

   local Attacking = script.Parent["Attacking?"]

    script.Parent.Activated:Connect(function()
	if Attacking.Value == false then
		loadedAttackAnim:Play()
		Attacking.Value = true
		loadedAttackAnim.Stopped:wait()	
		Attacking.Value = false
	end
end)

If your bool name doesn’t have a question mark in it you shouldn’t include it there. Also if its a child of script.Parent, just do script.Parent.Attacking > there could possibly be something wrong with the animation part, but we don’t have the full script from what I see. If you have any more trouble, use prints to find where it prints and where the error cuts off. It’ll help in the future.

So, I tried multiple things to narrow down the issue.

Attacking = script.Parent.Attacking

script.Parent.Activated:Connect(function()
	if Attacking.Value == false then
		loadedAttackAnim:Play()
		Attacking.Value = true
		loadedAttackAnim.Stopped:wait()	
		Attacking.Value = false
	end
end)

while wait() do
	local Value = script.Parent.Attacking
	print(Value.Value)
end

Its printing false and true as it should, but in the value in the explorer, its not changing. Its constantly saying false. The reason I need it to change between false and true with 100% garuntee is because im using a function in a module that requires the value of Attacking through the localscript.

I don’t think there is nothing wrong with your script.

For me when I change the value of a value (with a script) it doesn’t change on the client, but if you change to the server it’s different.

1 Like

So you’ll wanna avoid using loops like that with functions, it’ll break the script. Idk if you tested it without it, but you can throw that loop in a spawn or coroutine to fix it.

Simple way -
Spawn(function()
–code here
end)

Attacking = script.Parent.Attacking

script.Parent.Activated:Connect(function()
	if Attacking.Value == false then
		loadedAttackAnim:Play()
		Attacking.Value = true
		loadedAttackAnim.Stopped:wait()	
		Attacking.Value = false
	end
end)

spawn(function()
     while wait() do
	     local Value = script.Parent.Attacking
	     print(Value.Value)
     end
end)

Nope, theres something wrong. I deleted the value from the explorer yet it is still printing the value.
I’ll look into it tomorrow, but I think im changing the value wrong.

Try this:

Local Attacking = false
script.Parent.Activated:Connect(function()
	if Attacking == false then
		loadedAttackAnim:Play()
		Attacking = true
		loadedAttackAnim.Stopped:wait()	
		Attacking = false
	end
end)

your code works
Baseplate.rbxl (21.9 KB)
Changes are seen in the explorer as long as you are in client mode. Probably the problem is the animation (some configuration).
Also, note that if you are changing a Boolvalue in a LocalScript, the change will not be replicated to the server, so the module that requires the BoolValue must be required locally