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
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)
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.