Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Keydown isn't working? [ANSWERED]

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!

3 comments

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.

0

The Keydown part worked, but the KeyUp part didnt.

0

Why aren't you using the Byte() ?

3 answers

✓ Accepted answer

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

1 comment

0

it doesn't stop printing keydown when I release the key though.

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

This worked for me. Hope it helps.

mouse.KeyDown:connect(function(key)
	if string.byte(key) == 13 then
		print("Enter")
	end
end)

3 comments

0

Didnt work.

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

0

THANK YOU! IT FINALLY WORKED

This discussion is preserved as it was. New answers, comments, and votes are closed.