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")