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

Keydown to a Enum.KeyCode. function? [EDITED]

Asked by 6 years ago
Edited 6 years ago

Shift to run

Code is not working

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local UserInputService = game:GetService('UserInputService')



UserInputService.InputBegan:Connect(function(input)



if  input.KeyCode == Enum.KeyCode.W then
Enum.KeyCode.W  = true
elseif Key:byte() == 48 then
Enum.KeyCode.LeftShift = true
end

if  input.KeyCode == Enum.KeyCode.LeftShift then
Player.Character.Humanoid.WalkSpeed = 38
end
end)


UserInputService.InputBegan:Connect(function(input)

if input.KeyCode == Enum.KeyCode.W then
input.KeyCode = Enum.KeyCode.W == false
elseif Key:byte() == 48 then
input.KeyCode = Enum.KeyCode.LeftShift == false
end

if not input.KeyCode == Enum.KeyCode.W or not input.KeyCode == Enum.KeyCode. LeftShift then
Player.Character.Humanoid.WalkSpeed = 16
end
end)

0
I learned from senior programmers that keydown is depreciated, going to change the script now robloxquestionnaire1 30 — 6y
0
Hey, I'm not that old. TheeDeathCaster 2368 — 6y

1 answer

Log in to vote
0
Answered by
Eqicness 255 Moderation Voter
6 years ago
Edited 6 years ago

Hello,

You're trying to set an Enum: Enum.KeyCode.W = true. You do this with multiple different key codes. This is not logical, and will throw an error.

You also need to use InputEnded to check when the player stops pressing a key. You're using InputBegan twice.

Also, you're using an outdated Key:byte(), when Key isn't even defined.

You need to check over your script and read your errors before asking for help on Scripting Helpers. We are here if you can't solve an error even after looking at your output and checking your script, or if you can't figure out how to do something.

Hope this is helpful,

Eqic.

Ad

Answer this question