:InputEnded() function isn't working

So I’m working on a shift to sprint function, nothing too crazy, but something kinda weird is happening. My :InputBegan() function is working as intended, but the :InputEnded() function isn’t, despite using the same conditional statement to confirm that either the LeftShift or RightShift button is being held down (or in this case, being let up). The initial line is running, as shown when adding a print() statement after it, but the code stops working when it gets to line 9. No clue why this isn’t working as it’s practically identical to the :InputBegan() function, just in reverse. Thanks for the help in advance!

local input = game:GetService("UserInputService")

local players = game:GetService("Players")
local localplayer = players.LocalPlayer
local moving = false

input.InputEnded:Connect(function(key, __gameProcessed)
	if not __gameProcessed then
		if key == Enum.KeyCode.LeftShift or key == Enum.KeyCode.RightShift then
			print("Player has stopped.")
			localplayer.Character:WaitForChild("Humanoid").WalkSpeed = 20
			moving = false
		end
	end
end)
1 Like

Did a quick search:

That doesn’t really work in my case… Also, I did research my problem before posting this, like most people do, so giving links to other topics isn’t really helpful.

The ‘key’ variable is actually an input object, and one of its properties is inputObj.KeyCode. What would work in your exact case would be ‘key.KeyCode’. ‘key’ as an input object gives all the necessary information about the input. It may be a mouse button click, game controller button press, key on a keyboard, key on a virtual keyboard and so forth.

1 Like

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