Help with "Run with W" script

So I’ve got a running local script and I’ve set it so that when the player presses W, (moves forwards) then the character runs. It worked the first time but now it doesn’t work and completely disables the player from moving forwards. Can anyone help me with this?
Here’s the local script.

	local Character = workspace:WaitForChild(Player.Name)
		local Humanoid = Character:WaitForChild('Humanoid')
		
local RunAnimation = Instance.new('Animation')
RunAnimation.AnimationId = 'rbxassetid://16922184998'
RAnimation = Humanoid:LoadAnimation(RunAnimation)

Running = false

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

Humanoid.Running:connect(function(Speed)
	if Speed >= 10 and Running and not RAnimation.IsPlaying then
		RAnimation:Play()
		Humanoid.WalkSpeed = 20
	elseif Speed >= 10 and not Running and RAnimation.IsPlaying then
		RAnimation:Stop()
		Humanoid.WalkSpeed = 16
	elseif Speed < 10 and RAnimation.IsPlaying then
		RAnimation:Stop()
		Humanoid.WalkSpeed = 16
	end
end)

Humanoid.Changed:connect(function()
	if Humanoid.Jump and RAnimation.IsPlaying then
		RAnimation:Stop()
	end
end)

game:GetService('ContextActionService'):BindAction('RunBind', Handler, true, Enum.KeyCode.W)

Use a script not a local script.

Where would I put that script?

I put the script in StarterPlayerScripts and it didn’t work.

I might be blind, but how do you get the player?

1 Like

Ah sorry, I didn’t copy the very first line of the script. The player is found using local Player = game.Players.LocalPlayer .

Maybe try using Humanoid.Animator:LoadAnimation()

I’m not sure if that would fix it, since the animation plays just fine. It’s just that the player can’t move forwards.

Binding an action through ContextActionService can override existing actions that use the same input. After testing, I concluded that BindAction, by default, has the same priority as Enum.ContextActionPriority.Medium, which is the one Roblox uses in the movement system. I would suggest using UserInputService for what you’re trying to achieve.

1 Like

Ok u cant use a script for search a player, but u cant even use a local script (in this case)

Thanks so much! I changed it to use UserInputService and it works now!

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