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

How to detect key press in normal script?

Asked by 5 years ago

please.

UserInputService and Mouse.KeyDown()is only for local script.

How can I detect key press with normal script??

0
Why would you do it in a server script? The mouse is a local .. thing. ForeverBrown 356 — 5y
0
If you need to get input in a Server script, you're doing something wrong. If I were you I would review your code turtle2004 167 — 5y
0
comments might seem a bit harsh, but theyre right when they're saying that you should detect key presses on a local script. server scripts are for dealing with all the interactions between the players in the game whereas local scripts are for dealing with the individual player. tell us what you are trying to do and we'd be happy to help you do that. i just think your approach to the problem might royaltoe 5144 — 5y
0
not work / might not be best for what you're trying to do, but that's okay, it comes with practice. just to let you know, local scripts should be for logic handling the individual player like when the INDIVIDUAL player presses THEIR key, or when the INDIVIDUAL player presses THEIR gui. regular scripts are more for interaction in the game such as when A player TOUCHES a brick in game royaltoe 5144 — 5y
View all comments (3 more)
0
scripts on the server are for everyone where a local script is for the individual player. server scripts are for logic that everyone can access and make changes that other players can see where as local scripts are for changes that only the player playing your game can see. if you want things in a local script to be seen by everyone on a server, use remote events for that (which is another topic) royaltoe 5144 — 5y
0
for now, try to explain what you're trying to do and we can guide you into the right direction royaltoe 5144 — 5y
0
@royaltoe Thank you! I just use remote event. Nakama_G 6 — 5y

4 answers

Log in to vote
1
Answered by 5 years ago

You can't.

Mouse and Keybaord events (as well as other input events) can only be handled in LocalScripts. https://developer.roblox.com/en-us/articles/introduction-to-input

Ad
Log in to vote
0
Answered by 5 years ago

Mouse.Button1Down()

is when clicking

local KEYW = "Key"

Mouse.KeyDown:Connect(function(key)
    if key == KEYW then

    end
end)

is when key

0
I said normal script not local script... Nakama_G 6 — 5y
Log in to vote
0
Answered by 5 years ago

Use a localscript for the mouseclick then use a remote to fire an event to the script.

Log in to vote
0
Answered by 5 years ago

It's not possible to detect a key press or mouse button press from a server script, as these are both local things. If you want something to happen in a server script when a key press or mouse button press is detected, use a RemoteEvent and fire the server from a LocalScript when pressed.

Answer this question