Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 5 years ago

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

1UIS = game:GetService("UserInputService")
2 
3UIS.InputBegan:Connect(function(Input)
4    if Input.KeyCode == Enum.KeyCode.M then
5    print("hi")
6    --print(Input.Name)
7    --print(Input.Parent.Name)
8    end
9end)

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

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 iDarkGames 483 — 5y
0
OH MY ###### PIECE OF ## THIS WORKS, I PUT IT IN STARTER PLAYERSCRIPTS AND IT WORKS. CommanderCaubunsia 126 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

Put it in starter player scripts.

Here's an example of what you could do:

1game:GetService("UserInputService").InputBegan:Connect(function(input)
2    if input.KeyCode == Enum.KeyCode.M then
3        local Event = Instance.new("RemoteEvent")
4        Event.Name = "MKeyPressed"
5        Event:FireServer()
6    end
7end)
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. CommanderCaubunsia 126 — 5y
0
Ok? Also, it does work. FrostedFlakes67 71 — 5y
Ad

Answer this question