Boolvalue wont update, but updates in script

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I want the bool value (isSwinging) to change when you click with the tool.

  1. What is the issue? Include screenshots / videos if possible!

When I click while ingame with the tool equipped, the boolvalue doesnt change, but the print command shows that its changing.

Script Picture:

Video:

Normal script thats in the Tool in StarterPack:

local tool = script.Parent
local isSwinging = tool.isSwinging
local animation = tool.Animation
isSwinging = false

tool.Activated:Connect(function()
	if isSwinging == false then
		isSwinging = true
		local character = tool.Parent
		local humanoid = character.Humanoid
		print(isSwinging)
		local AnimationTrack = humanoid:LoadAnimation(animation)
		AnimationTrack:Play()
		wait(0.45)
		isSwinging = false
		print(isSwinging)
	end
end)


If there are better practices, I would like to know! :+1:

1 Like

When working with bool values you need to access the .Value property to change its value (same thing with other value instances), in this case to solve your issue, simply add .Value (directly after isSwinging) in the following places:

Here

Here

Here

And here.

Basically why it was “changing in the script” but not studio was because on this line:

You essentially made the variable just true or false and not the isSwinging value, so that variable was changed from there on and not the actual bool value since you forgot .Value

isSwinging should be changed about its isSwinging.Value when you are talking about the BoolValue. Changing the variable directly will result in changing the entire variable pointing to a boolean instead.

I guess you were looking at the right one …

Oh, I did put .Value before, but I didn’t put it on the local isSwinging, so I guess that’s why I was confused. Ty for the help

1 Like

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