How do i fix this running script bug?

Reposting because some mod decided to delete my post for literally no reason.
code:

local context = game:GetService("ContextActionService")
local runbind = "RunBind"
local Player = game.Players.LocalPlayer
	local Character = workspace:WaitForChild(Player.Name)
		local Humanoid = Character:WaitForChild('Humanoid')
		
local RunAnimation = Instance.new('Animation')
RunAnimation.AnimationId = 'rbxassetid://9980814558'
RAnimation = Humanoid:LoadAnimation(RunAnimation)

Running = false

function Handler(BindName, InputState)
	if InputState == Enum.UserInputState.Begin and BindName == runbind and Humanoid.WalkSpeed == 16 then
		Running = true
		Humanoid.WalkSpeed = 25
	elseif InputState == Enum.UserInputState.End and BindName == runbind and Humanoid.WalkSpeed == 25
	then
		Running = false
		if RAnimation.IsPlaying then
			RAnimation:Stop()
		end
		Humanoid.WalkSpeed = 16
	end
end

Humanoid.Running:connect(function(Speed)
	if Humanoid.WalkSpeed == 25 and not RAnimation.IsPlaying then
		RAnimation:Play()
	else
		if Humanoid.WalkSpeed == 16 and RAnimation.IsPlaying then
			RAnimation:Stop()
		end
	end
	
end)

context:BindAction(runbind , Handler, true, Enum.KeyCode.LeftShift)
context:SetPosition(runbind, UDim2.new(.5, 0, .3, 0))
local button = context:GetButton(runbind)
button.Size = UDim2.new(.3, 0, .4, 0)
context:SetTitle(runbind, "Run") 

when you open the pause menu (which i made) which disables the script the animations bug. You run when you don’t move and when you actually run it’s the running animation but it stops. Video:

2 Likes

What disabling this script does? Does it make player’s character unable to move?
Edit: I think that this isn’t what it does but I want to be sure.

opening the pause menu sets your walkspeed to 0, disables thumbstick for mobile and disables running so you can’t move.

1 Like

Try adding a line of code which stops the running animation as soon as RAnimation variable is declared;

--Some code above

local RunAnimation = Instance.new('Animation')
RunAnimation.AnimationId = 'rbxassetid://9980814558'
RAnimation = Humanoid:LoadAnimation(RunAnimation)

--Add this:
RAnimation:Stop()

--Some code below
local RunAnimation = Instance.new('Animation')
RunAnimation.AnimationId = 'rbxassetid://9980814558'
RAnimation = Humanoid:LoadAnimation(RunAnimation)
RAnimation:Stop()

Running = false

doesn’t work. i think it’s also making 2 animations but i can’t find the animations so i can delete it.

I think that I got an idea how to fix it but I will be able to explain it later.

Could you do it now? I’ll be able to use your fix in a few minutes kr an hour

Send the code of the script which disables the run script. It will make my explanation easier to understand.

I can’t send it rn, sorry! I have to do stupid homework lol.

That’s okay. You can do it later.

Instead of Humanoid.Running, try using Humanoid.MoveDirection and check if it is greater than 1. If it is, then play the animation, or else stop the animation.

2 Likes

finally done lmao. i hate algebra.

Players.bloodbonniekingnoob1.PlayerGui.RunningScript:28: attempt to compare number < Vector3

if Humanoid.MoveDirection > 1 then

Sorry. What I meant was that if the Humanoid.MoveDirection had any value, you should play the animation. Because the default value of MoveDirection is Vector3.new(nan,nan,nan) just do if Humanoid.MoveDirection == Humanoid.MoveDirection then (I think). This is because nan ~= nan.

if Humanoid.MoveDirection == Humanoid.MoveDirection then doesn’t even play the animations.

if Humanoid.MoveDirection == Humanoid.MoveDirection then
	if Humanoid.WalkSpeed == 25 and not RAnimation.IsPlaying then
		RAnimation:Play()
	else
		if Humanoid.WalkSpeed == 16 and RAnimation.IsPlaying then
			RAnimation:Stop()

Whats the animation priority?

maybe try highering the anim priority?

how? i suck at coding lmao char

My bad. I wasn’t sure if you could do that. Try:
humanoid.MoveDirection.Magnitude > 0
I thought that since MoveDirection was nan by default that it would just work like that but apparently not.

1 Like