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

How do I make a working detect Keydown event Script?

Asked by 5 years ago
Edited 5 years ago

Hi everybody, so i know they replaced the keydown thing and there is no more getmouse().keydown stuff, but imade a HUGE script:

local UIS = game:GetService("UserInputService")
can = true

UIS.InputBegan:connect(function(input)
    if can == true then
        can = false
*[this content was supposed to be the real script but this might be copied and someone might use it in the game they make and i dont want that especialy when you cant track those people, since this is a SCRIPT! and they can take my name out easily, so this content has been deleted, sorry]*
        can = true
    end
end)

and the thing is this does all this stuff when key pressed, i have debug yes its helpful, but i cant seem to have the specific keydown thing working, i took it out because i wanted to focus on waht the script actualy does so i dont waste a lot of time just on the keydown thing, but yeah i tried, it doesnt work i could be doing it wrong.., no debug, so this script since taken out specific key thing, when you press anything or click, this script works, for the actual action, so how can i make the server sense what key it specificaly is? and btw sorry grammer might be wrong but im hurrying because i have to go to a party! Anyone feel free to edit this to fix grammar. Thanks! :)

0
Oh and please dont critisize me, this other time there was a guy on one of my questions who said "Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer." even though i used comments AND explained what all lines did and how they interacted with eachother CommanderCaubunsia 126 — 5y
0
You must post all of your script and be more specific on what your issue is. You are being vague, sorry! checkerscat2 116 — 5y
0
Serverscriptservice*, and client scripts dont run in SERVER script service. Plus the server can't access client sided functions. Please lurn more about client and server blockmask 374 — 5y
0
Learn blockmask 374 — 5y
0
first thats rude and second it was just a try, its like your looking for a purse and you see a crack but say its too small to be in there, but it is in there because its bigger on the inside! CommanderCaubunsia 126 — 5y

2 answers

Log in to vote
2
Answered by
blockmask 374 Moderation Voter
5 years ago

There are several ways to do this. One can use UserInputService in order to accomplish this, another way is ContextActionService, and mouse.KeyDown, but I'm only going to tell you UserInputService and ContextActionService

When using UserInputService, I'd recommend using a variable to define it, and then connecting it to an InputBegan function

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input, typing)
    if input.KeyCode == Enum.KeyCode.W and not typing then
        --What happens when they're holding W
    end
end)

and then you have to close it off with the InputEnded

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input, typing)
    if input.KeyCode == Enum.KeyCode.W and not typing then
        --What happens when they're holding W
    end
end)

UIS.InputEnded:Connect(function(input, typing)
    if input.KeyCode == Enum.KeyCode.W and not typing then
        --What happens when they finished holding W
    end
end)

Now for ContextActionSerivce store it in a variable, then bind the action

local Context = game:GetService("ContextActionService")

local functionR = function(actionName, actionInputState, actionInputObject)
     if actionInputState == Enum.UserInputState.Begin then
        --What happens when holding w
     end
end

Context:BindAction(
    "actionName",
    functionR,
    false, -- Makes a button on their screen(mobile)
    "w" -- The button they need to press on Pc
)

Also, mouse.KeyDown() is deprecated, please do not use it.

I hope I helped!

0
XD ... <:D... :o ... :/ it, it didnt, work... ITS NOT FAIR, WHY DOES IT NEVER WORK, ALL I NEED IS ONE THING, TO DETECT A KEYDOWN THATS ALL AND ITS TAKEN SO LONG WITH ANSWERS thAT DONT WORK!. CommanderCaubunsia 126 — 5y
0
calm down buddy i got an idea bro ;D idunnobut 27 — 5y
0
use a local script, place it in startergui. Please learn more about client and server blockmask 374 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

Hello, i dont know why but i just like answering these guy's questions- anyways i think i know the PROBLEM, so first things first, it may be you're device or it can be you're studio, and if you didnt know, studio is NOT the same as normal roblox player, so things can work in studio but not in roblox normal game, or vise versa, so instead of using studio to test it, teast actualy PLAYING YOUR GAME, remember; you dont need to have a game thats not private, it can be private, butthe owner will always be able to play it, later ill come back :)

0
nope, it never works, i tried the same script other guy gave me and to debug it (to test id it works) i made it so when key pressed it supposed to spawn a brick in front of me. Instance.new("Part",game.Workspace).CFrame = (mycharacter).Head.CFrame,  SOMEONE HELP MEEEE WHY NO WORKING!?!!?? CommanderCaubunsia 126 — 5y
0
omg i just needed local script XD ok done thanks :) CommanderCaubunsia 126 — 5y

Answer this question