Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would I make an animation stop when the user hits the ground?

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)

3 comments

0

I'm sorry if I don't respond for a while, it's because I'm going to bed right now, I just figured I'd post this real quick first.

0

I would use the event HumanoidStateChanged

0

That animation's a bit funny are you sure you don't want to keep it? Or does it stop the player's movement while you're in the paused state?

1 answer

✓ Accepted answer

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.

5 comments

0

Yeah, okay. Thanks!

0

Okay, well it still does the same thing. I don't think it's a problem in the script to be honest, I think it's something with the actual animation. Why wouldn't it just stop though?

0

I'll still accept your answer though since you basically answered my question, it just turns out I was asking the wrong question.

0

Okay, so wait, I'm noticing something suspicious. So I added a cooldown to the move using a boolean variable, and the cooldown is set to 3 seconds. The animation stays in that paused state exactly for that 3 seconds. I'ma look more into this.

0

Oh duh I think I just realized the problem. I forgot to stop the first animation, so the first animation kept playing for the last 3 seconds of the cooldown.

This discussion is preserved as it was. New answers, comments, and votes are closed.