game.ReplicatedStorage.HoldAssaultRifleEvent.OnServerEvent:Connect(function(player, gun)
local HoldAssaultRifleAnimationTrack = player.Character.Humanoid:LoadAnimation(gun.HoldAssaultRifleAnimation)
gun.IsEquipped.Value = true
while true do
if gun.IsEquipped.Value == true then
HoldAssaultRifleAnimationTrack:Play()
wait(30)
else
gun.IsEquipped.Value = false
break
end
end
end)
game.ReplicatedStorage.StopHoldingAssaultRifleEvent.OnServerEvent:Connect(function(player, gun)
local HoldAssaultRifleAnimationTrack = player.Character.Humanoid:LoadAnimation(gun.HoldAssaultRifleAnimation)
HoldAssaultRifleAnimationTrack:Stop()
end)
if gun.IsEquipped.Value == true then
HoldAssaultRifleAnimationTrack:Play()
wait(30)
elseif gun.IsEquipped.Value == false then
HoldAssaultRifleAnimationTrack:Stop()
why are you waiting on 30 seconds seems to be a bad delay instead just use Animation.Stopped:wait()
game.ReplicatedStorage.HoldAssaultRifleEvent.OnServerEvent:Connect(function(player, gun)
local HoldAssaultRifleAnimationTrack = player.Character.Humanoid:LoadAnimation(gun.HoldAssaultRifleAnimation)
gun.IsEquipped.Value = true
while true do
if gun.IsEquipped.Value == true then
HoldAssaultRifleAnimationTrack:Play()
HoldAssaultRifleAnimationTrack.Stopped:wait() -- then after this code anything you want below it
else
gun.IsEquipped.Value = false
break
end
end
end)
I figured it out the problem was that I forgot to set the IsEquipped Value to false when the player unequips the weapon, so it kept playing the animation.