Can you not use a boolvalue in an if statement?

so basically i am trying to make it so if the boolvalue is true an anim plays aka player equips tool which triggers a function that changes the value of the boolvalue to true.

local IsHeld = tool.IsHeld

local function onEquipped(isequipped)
	IsHeld.Value = true
end
local function unEquipped(isequipped)
	IsHeld.Value = false
end


tool.Equipped:Connect(onEquipped) 

tool.Unequipped:Connect(unEquipped) 

if IsHeld.Value == true then
	print("@")
	HoldAnim = humanoid:LoadAnimation(Anim)
	HoldAnim:Play()
else
	HoldAnim:Stop()
end

but the thing is that the functions do make the boolvalue true/false but the if statement doesnt do anything

image

Are you doing this on a LocalScript or the Server? This should work.

However it could be that you aren’t checking this, This will only fire once

no its on a script under a tool in the players inventory

As what @DasKairo said, the given if statements will only run once. A simple fix to this is to connect the Changed event to the Boolean value (GetPropertyChangedSignal() is another option) .

local IsHeld = tool.IsHeld

HoldAnim = humanoid:LoadAnimation(Anim)

local function onEquipped(isequipped)
	IsHeld.Value = true
HoldAnim:Play()
end
local function unEquipped(isequipped)
	IsHeld.Value = false
HoldAni
end


tool.Equipped:Connect(onEquipped) 

tool.Unequipped:Connect(unEquipped) 

if IsHeld.Value then
	print("@")
	HoldAnim = humanoid:LoadAnimation(Anim)
	HoldAnim:Play()
else
	HoldAnim:Stop()
end

IsHeld.Changed:Connect(function()
	if IsHeld.Value then
		print("@")
		HoldAnim = humanoid:LoadAnimation(Anim)
		HoldAnim:Play()
	else
		HoldAnim:Stop()
	end
end)

However, I don’t think this would be necessary as you can just play the animation (and stop it) in the Equipped and Unequipped events, unless there’s another reason why you have a Boolean value to determine when to play the animations.

local IsHeld = tool.IsHeld
HoldAnim = humanoid:LoadAnimation(Anim)

local function onEquipped(isequipped)
	HoldAnim:Play()
	IsHeld.Value = true
end
local function unEquipped(isequipped)
	HoldAnim:Stop()
	IsHeld.Value = false
end


tool.Equipped:Connect(onEquipped) 

tool.Unequipped:Connect(unEquipped)
1 Like

yeah ima just gonna do that instead i was gonna use the boolean value way because i was planning on doing something with it but whatever

That’s Kind of rude to Give yourself the Solution instead of Someone who actually helped with Explaining on what to do.

2 Likes

I believe the solution should go to my post above because it explains the real problem and the solution to your issue. It can also be helpful for others who may have a similar issue.

2 Likes

uh ok mb then ig il change it if i can

but then again he didnt explain anything he just suggested an alternate version that i already had as a possible alternative

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