User input service not working

I’m having trouble getting user input service to work correctly, and I don’t know why. I’m trying to make a flight script, and I followed a tutorial for it, but it’s not working.

local uis = game:GetService("UserInputService")

I defined user input service at the beginning.

uis.InputBegan:connect(function(input)
	print("key pressed")
	if input.KeyCode == Enum.KeyCode.F then
		print("f pressed")
		if not flying then
			print("flying")
			fly()
		else
			print("not flying")
			endFlying()
		end
	end
end)

and I printed all the combinations, but none of them work.

2 Likes

Just tested the script and it worked perfectly

Okay, let me restart my studio or something.

It needs to be a localscript, if it isn’t already

It is, restarting my studio didn’t do anything either.

Where is the LocalScript located?

Is that the whole script ? if not can you show the whole script so we can help. (:

I scrapped the script because I found a different one that worked better, sorry for wasting everyone’s time.