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

Keydown isn't working? [ANSWERED]

Asked by 10 years ago

I'm trying to make the player's walkspeed change to 30 while the enter key is being held down. And when it gets released, it changed back to 16.

But its not working

Script:

01plr = script.Parent.Parent
02mouse = plr:GetMouse()
03 
04mouse.KeyDown:connect(function(key)
05    if key == 13 then
06        plr.Character.Humanoid.WalkSpeed = 30
07    end
08end)
09 
10mouse.KeyUp:connect(function(keyy)
11    if keyy == 13 then
12        plr.Character.Humanoid.WalkSpeed = 16
13    end
14end)

THIS IS A NORMAL SCRIPT INSIDE STARTERPACK!

0
To me, personally, it may be because your using a Server-Sided script, and not a Client-Sided script, because, I think 'GetMouse' can only be called from a Client-Sided script because of the 'LocalPlayer''s mouse, but, that's just me. TheeDeathCaster 2368 — 10y
0
The Keydown part worked, but the KeyUp part didnt. Operation_Meme 890 — 10y
0
Why aren't you using the Byte() ? woodengop 1134 — 10y

3 answers

Log in to vote
0
Answered by 10 years ago

LOALSCRIPT

01plr = game.Players.LocalPlayer
02m = plr:GetMouse()
03down = false
04 
05 
06m.KeyDown:connect(function(key)
07    if key:lower() == "r" then
08        down = true
09        repeat
10            print('keydown')
11            wait()
12        until
13        down==false
14    end
15end)
View all 22 lines...
0
it doesn't stop printing keydown when I release the key though. Operation_Meme 890 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

You should give this a shot...

01plr = game.Players.LocalPlayer
02m = plr:GetMouse()
03hold = false
04 
05function holdingkey()
06    while hold == true do
07        plr.Character.Humanoid.WalkSpeed = 30
08    end
09end
10 
11m.KeyDown:connect(function(key)
12    if key == 13 then
13        hold = true
14        holdingkey()
15    end
View all 22 lines...
Log in to vote
-1
Answered by 10 years ago

This worked for me. Hope it helps.

1mouse.KeyDown:connect(function(key)
2    if string.byte(key) == 13 then
3        print("Enter")
4    end
5end)
0
Didnt work. Operation_Meme 890 — 10y
0
Mouse is available in local scrips meanig a remote function is neede, here is my working copy http://www.filedropper.com/place1_1 Also this will now work with filtering enabled for better game security User#5423 17 — 10y
0
THANK YOU! IT FINALLY WORKED Operation_Meme 890 — 10y

Answer this question