KeyUp randomly triggers?

So I have a keyup event which I use to put someones arm down. But for some reason, this keeps randomly triggering for no reason. Sometimes it works, other times it triggers randomly.

mouse.KeyUp:connect(function(key)
if key:lower() == "q" then
if fire then
repeat wait() until ready == true
changeWeight(fire, 0, .3)
ready = false
end
end
end)

I have defined all variables.

local function changeWeight(animationTrack, weight, fadeTime)
animationTrack:AdjustWeight(weight, fadeTime)
local startTime = tick()
while math.abs(animationTrack.WeightCurrent - weight) > 0.001 do
	wait()
end
animationTrack:Stop()
end
1 Like

You should be aware that KeyUp is actually deprecated and shouldn’t be used anymore.

Instead, you should utilise UserInputService where you will be able to detect an input from the user from using InputBegan. Likewise, if you want to detect when a user input ends, you can use InputEnded.

7 Likes

I did that, but it still tends to happen randomly sometimes. For now, its a good temporary fix.

No, UserInputService is what you should be using. Your previous method is a temporary fix, not UserInputService.

Any issues with what behavior you see is not with UserInputService, it is with your own code.

1 Like

Alright, I will look into my code more closely.