I have a code that stops a animation at a certain point, the code would work some of the times but it wouldn’t always work. Right now I’m using the GetMarkerReachedSignal event to stop it:
animation:GetMarkerReachedSignal("Casting"):Connect(function()
animation:AdjustSpeed(0)
end)
I have also tried using another method to stop the animation, which was the AnimationStopped event. But that didn’t always work too:
animation.Stopped:Connect(function()
animation:AdjustSpeed(0)
end)
Edit - Here’s my full script just in case:
local FlamethrowerPart = game.ServerStorage.Magics.Fire.FlamethrowerPart
local FlamethrowerEvent = game.ReplicatedStorage.Magics.Fire:WaitForChild("Flamethrower")
local TweenService = game:GetService("TweenService")
local hitTable = {}
local damaged = {}
local dmg = 2
local burnlength = 4
local speed = 20
local StunDuration = 0.2
local lifetime = 2
local amountofparts = 8
local animid = "rbxassetid://10808173944"
FlamethrowerEvent.OnServerEvent:Connect(function(player)
local humanoid = player.character:WaitForChild("Humanoid")
game.ReplicatedStorage.GlobalCd.MoveStart:FireClient(player)
local castanim = Instance.new("Animation")
castanim.AnimationId = animid
local animation = humanoid:LoadAnimation(castanim)
animation:Play()
local oldws = humanoid.WalkSpeed
local oldjp = humanoid.JumpPower
humanoid.WalkSpeed = 2
humanoid.JumpPower = 0
animation:GetMarkerReachedSignal("Casting"):Connect(function()
animation:AdjustSpeed(0)
end)
task.wait(0.5)
local newFlamethrower = FlamethrowerPart:Clone()
for i = 1,amountofparts,1 do
local newFlamethrower = FlamethrowerPart:Clone()
newFlamethrower.Parent = game.Workspace
newFlamethrower.CFrame = player.character.HumanoidRootPart.CFrame*CFrame.new(Vector3.new(0,0,-1))
local BodyVelocity = Instance.new("BodyVelocity")
BodyVelocity.Parent = newFlamethrower
BodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
BodyVelocity.Velocity = player.character.HumanoidRootPart.CFrame.LookVector*speed
game.Debris:AddItem(newFlamethrower,lifetime)
local newThread = coroutine.create(function()
for i = 1,500,1 do
local x, y, z = math.random(-360,360), math.random(-360,360), math.random(-360,360)
newFlamethrower.Size = newFlamethrower.Size + Vector3.new(0.1,0.1,0.1)
newFlamethrower.Orientation = newFlamethrower.Orientation + Vector3.new(x,y,z)
task.wait()
end
end)
coroutine.resume(newThread)
newFlamethrower.Touched:Connect(function(hit)
if hit.Parent.Name ~= player.Name and hit.Parent:FindFirstChild("Humanoid") then
local ehumanoid = hit.Parent.Humanoid
table.insert(hitTable, ehumanoid)
for i = 1, #hitTable, 1 do
if table.find(damaged, ehumanoid) then return end
ehumanoid.Health -= dmg
local stuntag = Instance.new("ObjectValue")
stuntag.Name = "StunEffect"
stuntag.Parent = ehumanoid
game.Debris:AddItem(stuntag,StunDuration)
local burntag = Instance.new("ObjectValue")
burntag.Name = "BurnEffect"
burntag.Parent = ehumanoid
game.Debris:AddItem(burntag,burnlength)
local Tagged = Instance.new("ObjectValue")
Tagged.Name = "killer"
Tagged.Value = player
Tagged.Parent = ehumanoid
table.insert(damaged, ehumanoid)
end
end
end)
task.wait(0.12)
hitTable = {}
damaged = {}
end
humanoid.WalkSpeed = oldws
humanoid.JumpPower = oldjp
animation:AdjustSpeed(1)
game.ReplicatedStorage.GlobalCd.MoveFinish:FireClient(player)
end)
And here’s a video of an instance where the animation stops and an instance where it continues to play after I stopped it. (Btw, I don’t think the walking animation is causing this since the default walking animation causes this too):