*BUG* InputEnded Fires Randomly

So in my game I made a spriting system, easy right? In the game we have a hotbar as well where you can click 1, 2, 3 to equip weapons. Well while testing everything out I came across this really weird bug where I hold (W + Shift) and then while holding I click the key “2” Everything breaks. My player stops moving and inputs stop working for W A S D and then they start working after like 5 seconds. I tried literally everything to fix it and nothing worked. Heres the code I have for my sprinting system and it’s not really anything crazy which is why I am so confused why this is happening:

local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer

local MaxSpeed = false
local Sprinting = false

local CurrentSprint = Player:WaitForChild("Current")
local MaxSprint = Player:WaitForChild("Max")

local Depleted = Player:WaitForChild("Depleted")

local TS = game:GetService("TweenService")

local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

local FovInfoOut = TweenInfo.new(0.2, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
local FovInfoIn = TweenInfo.new(0.2, Enum.EasingStyle.Sine, Enum.EasingDirection.In)

local TimeSinceSprint = 0




UIS.InputBegan:Connect(function(input, gp)
	if gp then return end


	if input.KeyCode == Enum.KeyCode.LeftShift and CurrentSprint.Value > 0 and Sprinting == false then
		Sprinting = true
		MaxSpeed = false

		local TweenFov = TS:Create(workspace.CurrentCamera, FovInfoOut, {FieldOfView = 80})
		TweenFov:Play()

		local SpeedTween = TS:Create(Humanoid, TweenInfo.new(1), {WalkSpeed = 30})
		SpeedTween:Play()

		SpeedTween.Completed:Connect(function()
			MaxSpeed = true
		end)
	end
end)

UIS.InputEnded:Connect(function(input, gp)
	
	if input.KeyCode == Enum.KeyCode.LeftShift then
		if Sprinting then
			local TweenFov = TS:Create(workspace.CurrentCamera, FovInfoIn, {FieldOfView = 70})
			TweenFov:Play()

			Sprinting = false
		end
	end
end)

Obviously my actual code for the sprinting is below but I don’t want to bore with code everywhere. But the weird thing is that is if I do the combination (W + Shift + 2) and warn in InputEnded, IT FIRES. And Im like 99% sure this is a roblox bug where if ends all input for some reason when you press 2 with that combination, and literally any other Keyboard button doesn’t do it; If I press 1, 3, 4 … etc it doesn’t do it, but as soon as I click 2 while sprinting it stops and fires something called:

Enum.KeyCode.Unknown

So I tried to work around this and still nothing. The crazy part is I opened up a new baseplate because I though you know that it may have been another script that was messing it up and I put in the regular sprinting code and BOOM it still did it (Only with the Key 2). This bug is very critical because players in my game are going to continously switch weapons while sprinting and I don’t want them to leave because of this bug. Sorry to bore with so much, but I feel like this had to be explained throughouly because no one has ever posted something on this and I am confused if this is just me or not. But if anyone has any solutions or workarounds for this please help, thanks!

I can’t seem to replicate your issue, Enum.KeyCode.Unknown is for things that don’t have a keycode such as mouse inputs.

Mind if you show a video with console output open while it’s happening?

Hmmm weird, Open a new baseplate and put this code to see if it replicates:

local UIS = game:GetService("UserInputService")
local RunService = game:GetService("RunService")

local Sprinting = false
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Hum = Character:WaitForChild("Humanoid")


UIS.InputBegan:Connect(function(input, gp)
	
	
	if input.KeyCode == Enum.KeyCode.LeftShift and not Sprinting then
		Hum.WalkSpeed = 30
		Sprinting = true
	end
end)

UIS.InputEnded:Connect(function(input, gp)
	
	if input.KeyCode == Enum.KeyCode.LeftShift and Sprinting then
		Sprinting = false
		Hum.WalkSpeed = 16
	end
end)

Literally nothing in this baseplate just this script and thats it and the bug still occurs. Try to see if this happens for you, also I can’t send a video cause of the limits on here, but I will break down what happens

So if you click (W + LeftShift) and while holding those 2 you should be sprinting; After (while still holding) Click the Key 2 and your character should stop for some reason. I debugged this so many times, and whats happening is that when you click 2 while holding those two keys InputEnded fires for both W and LeftShift and you stop sprinting


Seems to work fine for me, what kind of keyboard do you have?

Hmmm I never thought about the keyboard issue, I have a 60% Keyboard it’s called the Newmen. That’s super weird, but while testing in the actual game my team member was experiencing the same issue and I am worried as to should I be concerned about this or not?

If the keyboard has some custom function with Shift + W or 2 then that might conflict with Roblox.

Yeah I don’t know can you give my game a test and see if it happens? My team member said his keyboard doesn’t have any special functionality and I just want to see if it does the same for you. Heres the link lmk what happens: Underground War 99! - Roblox


I don’t seem to be able to join the game at all :sweat_smile:

Edit: nvm seems to be fixed

Seems to work fine for me

Well I’ll be damned alright so it must just be the keyboard then. Thanks for the testing appreciate your time!

It could still be a Roblox bug, maybe test a bit more using some keyboard testing website to see if it’s sending some alternate key?

Where would I find this keyboard testing website?

or type “Keyboard test” in Google

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