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

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

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 4 years ago

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)
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 — 4y
Ad

Answer this question