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 9 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:

plr = script.Parent.Parent
mouse = plr:GetMouse()

mouse.KeyDown:connect(function(key)
    if key == 13 then
        plr.Character.Humanoid.WalkSpeed = 30
    end
end)

mouse.KeyUp:connect(function(keyy)
    if keyy == 13 then
        plr.Character.Humanoid.WalkSpeed = 16
    end
end)

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 — 9y
0
The Keydown part worked, but the KeyUp part didnt. Operation_Meme 890 — 9y
0
Why aren't you using the Byte() ? woodengop 1134 — 9y

3 answers

Log in to vote
0
Answered by 9 years ago

LOALSCRIPT


plr = game.Players.LocalPlayer m = plr:GetMouse() down = false m.KeyDown:connect(function(key) if key:lower() == "r" then down = true repeat print('keydown') wait() until down==false end end) m.KeyUp:connect(function(key) if key:lower() == "r" and down==true then down=false end end) --spyspace12
0
it doesn't stop printing keydown when I release the key though. Operation_Meme 890 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

You should give this a shot...

plr = game.Players.LocalPlayer
m = plr:GetMouse()
hold = false

function holdingkey()
    while hold == true do
        plr.Character.Humanoid.WalkSpeed = 30
    end
end

m.KeyDown:connect(function(key)
    if key == 13 then
        hold = true
        holdingkey()
    end
end

m.KeyUp:connect(function(key)
    if key == 13 then
        hold = false
    end
end
Log in to vote
-1
Answered by 9 years ago

This worked for me. Hope it helps.

mouse.KeyDown:connect(function(key)
    if string.byte(key) == 13 then
        print("Enter")
    end
end)
0
Didnt work. Operation_Meme 890 — 9y
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 — 9y
0
THANK YOU! IT FINALLY WORKED Operation_Meme 890 — 9y

Answer this question