Hello, I’m trying to make a weapon system in my game but when the animation is loaded in one event. With the other event that can’t stop the other loaded animation. Can someone help?
HoldTrack.AnimationId = "6887187273"
local Hold = player.Character.Humanoid:LoadAnimation(HoldTrack)
game.ReplicatedStorage.Events.StartAnim.OnClientEvent:Connect(function()
local Weapon = nil
for i,weapon in pairs(player.Character:GetChildren()) do
if weapon:IsA("Model") then
for i,v in pairs(game.ReplicatedStorage.Weapons:GetChildren()) do
if v.Name == weapon.Name then
Weapon = v
HoldTrack.AnimationId = Guns.GunInfo[Weapon.Name]["Hold"]
local Hold = player.Character.Humanoid:LoadAnimation(HoldTrack)
print(HoldTrack.AnimationId )
Hold:Play()
end
end
end
end
end)
game.ReplicatedStorage.Events.StopAnim.OnClientEvent:Connect(function()
print(HoldTrack.AnimationId )
Hold:Stop()
end)
It seems like you’re assigning 2 variables with the name “Hold” in 2 separate scopes. If you assign a variable something and then want to change it later you will need to call the name of the variable without “local” in front of it. If you don’t this will create a new variable instead of changing the old one.
local Number = 2
something.Touched:Connect(function()
local Number = 5
print(Number) -- 5
end)
print(Number) -- 2
To fix your issue since you already loaded the animation at the top of the script
local Hold = player.Character.Humanoid:LoadAnimation(HoldTrack)
you can get rid of this line inside of the .OnClientEvent event.
local Hold = player.Character.Humanoid:LoadAnimation(HoldTrack)
the default is there so the other OnClientEvents know what hold is so that they can have a variable because in my game all the weapons have a hold animation we want the specific animation to play for that weapon, so when you pull out the Bat the only animation played is the default first animation because there is no update to the animation