-
What do you want to achieve?
Making a knife grab game where if you grab a player you hold them hotstage, and when u stop walking or walk with them, its a different animation than the one when you don’t have anyone hostage. -
What is the issue?
The issue is, when i grab a player, and while walking i press MouseButton2 (Which is supposed to let go of the player) or i press MouseButton1 (while holding a player, its supposed to kill him) , the animation doesn’t stop and you still have the “HoldingWalk” and “HoldingIdle” set as your animaiton for walking and idleing; Video Of The Issue -
What solutions have you tried so far?
Tried using for i loops to get all anims track, and if they match the name, i stop them. But that doesnt seem to be working.
The Player.Stat is just a stat i change upon grabbing / letting go or killing the player, upon grabbing its set to “Grabbed”, on letting go or killing i set it to None, and thats how i change the animationTrack
local function oncharacteradded(character)
for _,v in pairs(events) do
v:Disconnect()
end
events = {}
local humanoid:Humanoid = character:WaitForChild("Humanoid")
local char = character
local styleValue = Player.Stat.Value
local walkanim = RepStorage.Animations.Walk
local idleanim = RepStorage.Animations.Idle
table.insert(events,Player.Stat.Changed:Connect(function(a)
local walkanim2 = RepStorage.Animations.WalkHold
local idleanim2 = RepStorage.Animations.HoldIdle
if a == "None" then
for i, v in ipairs(humanoid.Animator:GetPlayingAnimationTracks()) do
if v.Animation.Name == "HoldIdle" then
v:Stop()
walkanim2 = RepStorage.Animations.Walk
idleanim2 = RepStorage.Animations.Idle
end
end
end
idletrack = humanoid.Animator:LoadAnimation(idleanim2)
walktrack = humanoid.Animator:LoadAnimation(walkanim2)
if not walktrack.IsPlaying then
for i,v in pairs(humanoid.Animator:GetPlayingAnimationTracks()) do
if v.Animation.Name == "Idle" then
v:Stop()
end
end
idletrack:Play()
end
if not idletrack.IsPlaying then
for i,v in pairs(humanoid.Animator:GetPlayingAnimationTracks()) do
if v.Animation.Name == "Walk" then
v:Stop()
end
end
walktrack:Play()
end
end))
walktrack = humanoid.Animator:LoadAnimation(walkanim)
idletrack = humanoid.Animator:LoadAnimation(idleanim)
if humanoid.MoveDirection.Magnitude <=0 then
idletrack:Play()
end
table.insert(events,humanoid.Running:Connect(function(speed)
if humanoid.WalkSpeed < 20 and speed > 1 then
idletrack:Stop()
if not walktrack.IsPlaying then
walktrack:Play()
walktrack:AdjustSpeed(1)
end
else
walktrack:Stop()
if not idletrack.IsPlaying then
idletrack:Play()
end
end
end))
end