So, I'm trying to make a sort of dash, but it's in a move for an ability for my game. I got the move down, but the animation for the dash doesn't stop right. The animation just kind of pauses for a few seconds, then stops. Gyazo of what happens: https://gyazo.com/26c9866598398e9732e58a5b416274e4
Server:
tEvent.OnServerEvent:Connect(function(player,char) -- Character Stuff local humanoid = char.Humanoid local rootPart = char.HumanoidRootPart local rightHand = char.RightHand local leftHand = char.LeftHand -- Stats local stats = player.Stats local power = stats.Power local powerLevel = power.PowerLevel -- Clones local il = innerLeast:Clone() local im = innerMost:Clone() local ol = outerLeast:Clone() local om = outerMost:Clone() il.Parent = game.Workspace im.Parent = game.Workspace ol.Parent = game.Workspace om.Parent = game.Workspace local random1 = CFrame.Angles(math.random(0,360),math.random(0,360),math.random(0,360)) local random2 = CFrame.Angles(math.random(0,360),math.random(0,360),math.random(0,360)) local random3 = CFrame.Angles(math.random(0,360),math.random(0,360),math.random(0,360)) local random4 = CFrame.Angles(math.random(0,360),math.random(0,360),math.random(0,360)) il.CFrame = CFrame.new(rootPart.CFrame.X,rootPart.CFrame.Y,rootPart.CFrame.Z) * random1 im.CFrame = CFrame.new(rootPart.CFrame.X,rootPart.CFrame.Y,rootPart.CFrame.Z) * random2 om.CFrame = CFrame.new(rootPart.CFrame.X,rootPart.CFrame.Y,rootPart.CFrame.Z) * random3 ol.CFrame = CFrame.new(rootPart.CFrame.X,rootPart.CFrame.Y,rootPart.CFrame.Z) * random4 tEvent:FireClient(player) for i = 1,50 do local o = i local p = o*1.25 local q = p*1.25 local z = q*1.25 local x = i/70 + 0.5 local c = i/60 + 0.5 local v = i/50 + 0.5 local b = i/40 + 0.5 il.Size = Vector3.new(o,o,o) im.Size = Vector3.new(p,p,p) ol.Size = Vector3.new(q,q,q) om.Size = Vector3.new(z,z,z) il.Transparency = x im.Transparency = c ol.Transparency = v om.Transparency = b for i,v in pairs(game.Workspace:GetChildren()) do if v.ClassName == "MeshPart" and v == il or v == im or v == om or v == ol then local db = false v.Touched:Connect(function(hit) if db == false and hit.Parent.Name ~= "Model" and hit.Parent.ClassName == "Model" and hit.Parent.Name ~= player.Name then local humanoid = hit.Parent.Humanoid if humanoid then humanoid:TakeDamage((powerLevel.Value*0.05)*math.random(10,15)) db = true wait(1) db = false end end end) end end wait(0.01) end il:Destroy() im:Destroy() ol:Destroy() om:Destroy() end)
Client:
-- Player Stuff local player = game.Players.LocalPlayer local char = player.Character local humanoid = char:WaitForChild("Humanoid") local rootPart = char:WaitForChild("HumanoidRootPart") local UIS = game:GetService("UserInputService") -- Replicated Storage local repStorage = game.ReplicatedStorage local powers = repStorage:WaitForChild("Powers") local gasEvents = powers:WaitForChild("Gas Manipulation") local rEvent = gasEvents:WaitForChild("R") local tEvent = gasEvents:WaitForChild("T") local vEvent = gasEvents:WaitForChild("V") -- Cooldown Stuff local db1 = false local db2 = false local db3 = false local gasTrapCount = 0 local move1Cooldown = 0.5 local move1Extra = 24.5 local move2Cooldown = 3 local move3Cooldown = 40 -- Animations local dashAnim1 = "rbxassetid://2677606081" local dashAnim2 = "rbxassetid://2677611607" local dash1Wait = 0.25 UIS.InputBegan:Connect(function(key,isTyping) if not isTyping then if key.KeyCode == Enum.KeyCode.R and not db1 then gasTrapCount = gasTrapCount + 1 print(gasTrapCount) db1 = true rEvent:FireServer(char) wait(move1Cooldown) if gasTrapCount >= 5 then print("longer") wait(move1Extra) gasTrapCount = 0 end db1 = false elseif key.KeyCode == Enum.KeyCode.T and not db2 then db2 = true tEvent:FireServer(char) wait(move2Cooldown) db2 = false elseif key.KeyCode == Enum.KeyCode.V and not db3 then db3 = true vEvent:FireServer(char) wait(move3Cooldown) db3 = false end end end) tEvent.OnClientEvent:Connect(function() humanoid.Jump = true rootPart.Velocity = rootPart.Velocity + rootPart.CFrame.lookVector*200 local anim = Instance.new("Animation") anim.AnimationId = dashAnim1 local anim2 = Instance.new("Animation") anim2.AnimationId = dashAnim2 local dash1 = humanoid:LoadAnimation(anim) dash1.Priority = Enum.AnimationPriority.Action local dash2 = humanoid:LoadAnimation(anim2) dash2.Priority = Enum.AnimationPriority.Action dash1:Play() wait(dash1Wait) dash2:Play() while wait(0.1) do -- This is what stops the animation. if humanoid:GetState() ~= Enum.HumanoidStateType.Freefall and humanoid:GetState() ~= Enum.HumanoidStateType.Flying then dash2:Stop() break end end end)
Like kingdom said, you should use HumanoidStateChanged, this would go at where the while loop is.
humanoid.StateChanged:Connect(function(oldState, newState) if newState ~= Enum.HumanoidStateType.Freefall and newState ~= Enum.HumanoidStateType.Flying then dash2:Stop() end end)
I haven't used this in a long time, so if I got something wrong, just let me know because I also can't test this at the moment.