please.
UserInputService and Mouse.KeyDown() is only for local script.
How can I detect key press with normal script??
please.
UserInputService and Mouse.KeyDown() is only for local script.
How can I detect key press with normal script??
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
Mouse.Button1Down()
is when clicking
local KEYW = "Key"
Mouse.KeyDown:Connect(function(key)
if key == KEYW then
end
end)
is when key
I said normal script not local script...
Use a localscript for the mouseclick then use a remote to fire an event to the script.
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.
This discussion is preserved as it was. New answers, comments, and votes are closed.
7 comments
Why would you do it in a server script? The mouse is a local .. thing.
If you need to get input in a Server script, you're doing something wrong. If I were you I would review your code
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
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
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)
for now, try to explain what you're trying to do and we can guide you into the right direction
@royaltoe Thank you! I just use remote event.