Need help to make the animation stop when playing (+ need help with fixing a weird run animation glitch)

Hello,
I’m making an game and i tried to make an animation system. The problems are that they won’t stop when falling/Jumping and that the running animation plays weirdly for some reason (Possibly due to overlap). Tried to fix it, but I couldn’t. Can you guys help with fixing it? Thank you for your help and have a great day.

the ShifttoSprint Local Script:

local walkspeed = 7
local runspeed = 16
local brokenwalkspeed = 4
local brokenrunspeed = 14
local disablerun = false
local UIS = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local Replicated = game:GetService("ReplicatedStorage")
local Remote = Replicated:WaitForChild("Broken")

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local character = Player.Character or Player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:FindFirstChildOfClass("Animator") or Instance.new("Animator", humanoid)
local WalkAnim = script:WaitForChild("WalkAnim")
local WalkTrack = animator:LoadAnimation(WalkAnim)
local RunAnim = script:WaitForChild("RunAnim")
local RunTrack = animator:LoadAnimation(RunAnim)
local IdleAnim = script:WaitForChild("IdleAnimation")
local IdleTrack = animator:LoadAnimation(IdleAnim)

local acceleration = 0.2
local deceleration = 0.5
local running = false
local bonebroken = false

-- Reassign humanoid on character respawn
Player.CharacterAdded:Connect(function(char)
	character = char
	humanoid = char:WaitForChild("Humanoid")
end)

-- Smooth speed adjustment (acceleration + deceleration)
RunService.RenderStepped:Connect(function(deltaTime)
	if disablerun or not humanoid then return end

if humanoid.WalkSpeed == 0 then
humanoid.WalkSpeed = walkspeed	
else
	if bonebroken == false then
		if running then
			if humanoid.WalkSpeed < runspeed then
				humanoid.WalkSpeed = math.min(humanoid.WalkSpeed + acceleration, runspeed)
					WalkTrack:Stop()

					
			end
		else
			if humanoid.WalkSpeed > walkspeed then
				humanoid.WalkSpeed = math.max(humanoid.WalkSpeed - deceleration, walkspeed)
					RunTrack:Stop()
					humanoid.Running:Connect(function(Speed)
					end)
			end
		end
	else
			if running then
				if humanoid.WalkSpeed < runspeed then
					humanoid.WalkSpeed = math.min(humanoid.WalkSpeed + acceleration, brokenrunspeed)
				end
			else
				if humanoid.WalkSpeed > walkspeed then
					humanoid.WalkSpeed = math.max(humanoid.WalkSpeed - deceleration, brokenwalkspeed)
				end
			end
	end
end
end)

-- Input started
UIS.InputBegan:Connect(function(input, processed)
	if not processed and input.KeyCode == Enum.KeyCode.LeftShift then
		if not disablerun then
			running = true
		end
	end
end)

-- Input ended
UIS.InputEnded:Connect(function(input, processed)
	if not processed and input.KeyCode == Enum.KeyCode.LeftShift then
		if not disablerun then
			running = false
		end
	end
end)

-- Set default walkspeed on script start
humanoid.WalkSpeed = walkspeed

humanoid.Running:Connect(function(Speed)
	if humanoid.FloorMaterial == Air then
		WalkTrack:Stop()
		RunTrack:Stop()
		IdleTrack:Stop()
	else
		if Speed > 0.75 then
			if running == true then
				RunTrack:Play()
				IdleTrack:Stop()
			end
			if running == false then
				RunTrack:Stop()
				WalkTrack:Play()
				IdleTrack:Stop()
			end
		else
			WalkTrack:Stop()
			RunTrack:Stop()
			IdleTrack:Play()
		end
	end
end)


if UIS.TouchEnabled then
	local ui = Player.PlayerGui.MobileControls
	ui.Enabled = true
	
	ui.Frame.RunButton.MouseButton1Up:Connect(function()
		if running == false then
			running = true
		else
			running = false
		end
		wait(1)
	end)
end
1 Like

the videos:


humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function(value)
	if value == Enum.Material.Air then -- if floor material is air (jumping, falling)
		
		WalkTrack:Stop()
		RunTrack:Stop()
		IdleTrack:Stop()
		
	end
end)

So… tried to add and adjust the fix, but i couldn’t really get it to work. Any tips or ideas of how i could fix it? Just asking. Sorry if it sounds mean or disrespectful

local walkspeed = 7
local runspeed = 16
local brokenwalkspeed = 4
local brokenrunspeed = 14
local disablerun = false
local UIS = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local Replicated = game:GetService("ReplicatedStorage")
local Remote = Replicated:WaitForChild("Broken")

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local character = Player.Character or Player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:FindFirstChildOfClass("Animator") or Instance.new("Animator", humanoid)
local WalkAnim = script:WaitForChild("WalkAnim")
local WalkTrack = animator:LoadAnimation(WalkAnim)
local RunAnim = script:WaitForChild("RunAnim")
local RunTrack = animator:LoadAnimation(RunAnim)
local IdleAnim = script:WaitForChild("IdleAnimation")
local IdleTrack = animator:LoadAnimation(IdleAnim)

local acceleration = 0.2
local deceleration = 0.5
local running = false
local bonebroken = false

-- Reassign humanoid on character respawn
Player.CharacterAdded:Connect(function(char)
	character = char
	humanoid = char:WaitForChild("Humanoid")
end)

-- Smooth speed adjustment (acceleration + deceleration)
RunService.RenderStepped:Connect(function(deltaTime)
	if disablerun or not humanoid then return end

if humanoid.WalkSpeed == 0 then
humanoid.WalkSpeed = walkspeed	
else
	if bonebroken == false then
		if running then
			if humanoid.WalkSpeed < runspeed then
				humanoid.WalkSpeed = math.min(humanoid.WalkSpeed + acceleration, runspeed)

					
			end
		else
			if humanoid.WalkSpeed > walkspeed then
				humanoid.WalkSpeed = math.max(humanoid.WalkSpeed - deceleration, walkspeed)
					humanoid.Running:Connect(function(Speed)
					end)
			end
		end
	else
			if running then
				if humanoid.WalkSpeed < runspeed then
					humanoid.WalkSpeed = math.min(humanoid.WalkSpeed + acceleration, brokenrunspeed)
				end
			else
				if humanoid.WalkSpeed > walkspeed then
					humanoid.WalkSpeed = math.max(humanoid.WalkSpeed - deceleration, brokenwalkspeed)
				end
			end
	end
end
end)

-- Input started
UIS.InputBegan:Connect(function(input, processed)
	if not processed and input.KeyCode == Enum.KeyCode.LeftShift then
		if not disablerun then
			running = true
		end
	end
end)

-- Input ended
UIS.InputEnded:Connect(function(input, processed)
	if not processed and input.KeyCode == Enum.KeyCode.LeftShift then
		if not disablerun then
			running = false
		end
	end
end)



-- Set default walkspeed on script start
humanoid.WalkSpeed = walkspeed

humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function(value)
	if value == Enum.Material.Air then
		WalkTrack:Stop()
		RunTrack:Stop()
		IdleTrack:Stop()
	else
		humanoid.Running:Connect(function(Speed)
			if Speed > 0.75 then
				if running == true then
					RunTrack:Play()
					IdleTrack:Stop()
					WalkTrack:Stop()
				end
				if running == false then
					RunTrack:Stop()
					WalkTrack:Play()
					IdleTrack:Stop()
				end
			else
				WalkTrack:Stop()
				RunTrack:Stop()
				IdleTrack:Play()
			end
		end)
	end
end)


if UIS.TouchEnabled then
	local ui = Player.PlayerGui.MobileControls
	ui.Enabled = true
	
	ui.Frame.SprintButton.MouseButton1Up:Connect(function()
		if running == false then
			running = true
		else
			running = false
		end
		wait(1)
	end)
end
1 Like
humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function(value)
	if value == Enum.Material.Air then
		WalkTrack:Stop()
		RunTrack:Stop()
		IdleTrack:Stop()
	end
end)
humanoid.Running:Connect(function(Speed)
    if Speed > 0.75 then
        if running then -- if running is true
            RunTrack:Play()
            IdleTrack:Stop()
            WalkTrack:Stop()
        else -- if running is false
            RunTrack:Stop()
            WalkTrack:Play()
            IdleTrack:Stop()
        end
    else
        WalkTrack:Stop()
        RunTrack:Stop()
        IdleTrack:Play()
    end
end)

So… still strangely doesn’t work for some reason


. sorry if that sounded mean.

So… i actually found a solution. So… i modified the Animate script so a running animation plays when over speed 8. But thanks for the help. Sorry if i disappointed you or made you mad.

ah no problem. even i was asking myself why it doesnt work.

I’m asking the same. It’s strange

So… my theory is that the animation events (Play + Stop) prob overlaped due to the weird walking

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.