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

Why wont my W key pressed to hide a GUI script work?

Asked by
3Zj1 0
5 years ago

Im trying to make it so when you press W a GUI gets disabled but it says Expected ')' (to close '(' at line 2), got <eof>

i don't really understand scripting that well but i tried to fix it but couldn't

here is the script btw

local m = game.Players.LocalPlayer:GetMouse()
m.KeyDown:connect(function(k)
    k = k:lower()
    if k == "w" then
        script.Parent.Fist.Enabled = false
        end
    end

i tried adding ) to all around the second line but wouldn't help

(the title is weird because i had to make it "specific")

0
Don't use keydown, it is deprecated (old code), instead use UserInputService turtle2004 167 — 5y
0
It's because you're trying to use a Roblox Utilized key with the deprecated KeyDown service. Roblox will prevent you from using keys 0-9, W, A, S, D, I, O, (I believe L for whatever reason) due to core scripts already using them. Use UserInputService InputBegan. M39a9am3R 3210 — 5y
0
^ turtle2004 167 — 5y

2 answers

Log in to vote
0
Answered by
aazkao 787 Moderation Voter
5 years ago
Edited 5 years ago

the bracket is to close the Connect

local m = game.Players.LocalPlayer:GetMouse()
m.KeyDown:Connect(function(k)
    k = k:lower()
    if k == "w" then
        script.Parent.Fist.Enabled = false
        end
    end)--here
0
Keydown and Keyup are deprecated, refrain from using them in future. turtle2004 167 — 5y
0
Yes i know im answering based on his syntax errors aazkao 787 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

I'm assuming you do not know this, but KeyDown and KeyUp are deprecated. This means it's old code which shouldn't be used, as it may be buggy or there are better options available.Read this article for more info. So, you may be asking, what do I use if they're deprecated? Simple, UserInputService. Here's an example of it:

game:GetService("UserInputService").InputBegan:connect(function(input) --When a key is pressed...
    if input.KeyCode == Enum.KeyCode.W then --Check if the key is W
        -- Do something when W is pressed!
    end
end)

Now, i strongly recommend double checking your code for deprecated code, for example, :connect is deprecated too, instead use :Connect , with a capital C. Right, now we've got that over with let's mash your code and the new working code together:

game:GetService("UserInputService").InputBegan:connect(function(input)pressed...
    if input.KeyCode == Enum.KeyCode.W then
        script.Parent.Fist.Enabled = false --Change the boolean to False.
    end
end)

For future reference:

Useful Links:

UserInputService, ContextActionService and getting user input.

Why you shouldn't use deprecated code

0
Use connect, not Connect. Also, I recommend checking if the player is chatting or not. This way, the GUI won't close if the player is trying to chat. lunatic5 409 — 5y

Answer this question