I can't walk pressing W key

I wonder why I can’t walk pressing the W key, but other A, S, D keys are still working like normal. So, I think it might have something to do with my run script, which key bind with the W key, I think it might have something to do with context action key bind priority. But, I still don’t know how to fix it, please help me, thanks in advance.

Below is my whole run script that using W key

----------- Module ------------

local ContextActionService = game:GetService("ContextActionService")
local Tool = require(game.ReplicatedStorage.Tool)
local Players = game:GetService("Players")
local player = Players.LocalPlayer


----------- Main Function ------------

local last_run = tick()
local function Run(actionName, inputState, inputObject)

	if inputState == Enum.UserInputState.Begin then

		local now = tick()
		local difference = (now - last_run)

		if difference <= 0.5 then
			local character = player.Character or player.CharacterAdded:Wait()
			local humanoid = character:FindFirstChild("Humanoid")
			if humanoid then
				local playerstat = player:WaitForChild("playerstat")
				local agiLevel = playerstat:WaitForChild("Lv_AGI")
				local runSpeed = Tool:GetRunSpeed(agiLevel)
				if humanoid.WalkSpeed < runSpeed then
					local status = player:WaitForChild("status")
					local IsRunning = status:WaitForChild("IsRunning")

					IsRunning.Value = true
					humanoid.WalkSpeed = runSpeed
				end
			end
		end

		last_run = tick()

	elseif inputState == Enum.UserInputState.End then

		local character = player.Character or player.CharacterAdded:Wait()
		local humanoid = character:FindFirstChild("Humanoid")
		if humanoid then
			local playerstat = player:WaitForChild("playerstat")
			local agiLevel = playerstat:WaitForChild("Lv_AGI")
			local walkSpeed = Tool:GetWalkSpeed(agiLevel)

			local status = player:WaitForChild("status")
			local IsRunning = status:WaitForChild("IsRunning")

			IsRunning.Value = false
			humanoid.WalkSpeed = walkSpeed
		end

	end

end


----------- Main Connection ------------

ContextActionService:BindAction("Run", Run, true, "w")

2 Likes

I believe the error is that you arent unbinding the action?

1 Like

If you go to the roblox api and search for contextactionservice all of this is correct. String first, function second, boolean third, and tuple or button last.

1 Like

I don’t think unbind the action is the problem here, because my purpose is to make you run when double-tap the W key. So, I need it to bind all the time when player got add to the game.

Sorry to bring this up, but I still didn’t get the problem fix. Just for you to know that you still can reply to this post.

Maybe there’s an anchored part in the character?

Nope, every part in the character is unanchored. I can move pressing up arrow, but can’t move pressing W key.

Can you share me a video or a GIF?

Sorry, I didn’t update, but I already fixed that. Thanks for asking tho.

Old one:

ContextActionService:BindAction("Run", Run, true, "w")

New one:

ContextActionService:BindActionAtPriority("Run", Run, true, 0, "w")

So, basically, I guess it’s the bind action priority. When we first play in Roblox it gives the “W” key as a walk to the front action and gave it first priority. That’s why my run script did not work (because it has lower priority). So, what I do is to change the priority of it to 0 (which is the really first priority). Idk is it a good idea to do this, but if you have a better solution, you can suggest me.

1 Like