Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

My keydown event script doesnt work when i pres M, how do i fix it?

Iv done it before and have the same thing. All the sudden it doesnt work. i tried many things. but the two mains things were this code

UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(Input)
	if Input.KeyCode == Enum.KeyCode.M then
	print("hi")
	--print(Input.Name)
	--print(Input.Parent.Name)
	end
end)

and i tried it in a normal script and local script. both in workspace. also tried putting both in starterpack. it does not print hi when i press m in testing mode. please help

2 comments

1

You can only capture the input of the player in the client, I suggest you check a question I answered about where you can place your LocalScripts so your code works. https://scriptinghelpers.org/questions/55070/whats-the-best-place-to-store-local-scripts#53918

0

OH MY ###### PIECE OF ## THIS WORKS, I PUT IT IN STARTER PLAYERSCRIPTS AND IT WORKS.

1 answer

✓ Accepted answer

Put it in starter player scripts.

Here's an example of what you could do:

game:GetService("UserInputService").InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.M then
		local Event = Instance.new("RemoteEvent")
		Event.Name = "MKeyPressed"
		Event:FireServer()
	end
end)

2 comments

0

I ONLY ACCEPTED BECAUSE I HAD TO ACCEPT SOMETHING AND YOUR FIRST LINE WORKS. ALL THE OTHER STUFF I DONT THINK EVEN WORKS, YOU FORGOT TO PUT THE REMOTE EVENT IN SOMETHING LIKE REPLICATEDSTORAGE. whatever i answered so thanks i guess.

0

Ok? Also, it does work.

This discussion is preserved as it was. New answers, comments, and votes are closed.