Pressing other buttons stops running

so i want players do be able to run by pressing left control and it works, but the problem is that pressing any other button while running just stops the player running. i don’t know how to fix this and i have searched how to do it, but i can’t seem to find the solution. i’m new to scripting so i would appreciate if anyone just tell me what i did wrong in the script or forgot. also it happens when you press any other button than the ones being pressed before running.

local userInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer

local isRunning = false

userInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftControl and isRunning == false then
		player.Character.Humanoid.WalkSpeed = 32
		isRunning = true
	elseif isRunning == true then
		player.Character.Humanoid.WalkSpeed = 16
		isRunning = false
	
	end
end)

maybe add few more conditions before making isRunning false.

i found the solution, but your comment helped me find it. i just had to add something to the elseif condition thing.
i’m pretty sure it’s because if checks if a condition is true and elseif checks if another condition is true so by just writing elseif isRunning == true then
that just checks if isRunning is true but it doesn’t check if i press left control again to turn off running

elseif input.KeyCode == Enum.KeyCode.LeftControl and isRunning == true then

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