Problem: I for a game I am making I am try to add a run walk system in a Normal Script in StarterCharacterScripts but it isn’t working.
I Have tried to changing the if Statements to
if Input == Enum.KeyCode.--Key would go here
Code:
--getting UserInputService
local UserInputService = game:GetService("UserInputService")
--Key pressed event
UserInputService.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.LeftShift then
script.Parent.Humanoid.WalkSpeed = 100
elseif Input == Enum.KeyCode.LeftControl then
script.Parent.Humanoid.WalkSpeed = 1
end
end)
--Key let go event
UserInputService.InputEnded:Connect(function(Input, GameProcessedEvent)
if Input.KeyCode == Enum.KeyCode.LeftShift or Input.KeyCode == Enum.KeyCode.LeftControl then
script.Parent.Humanoid.WalkSpeed = 16
end
end)
Your code has to be in a local script. I would recommend putting it inside playerscripts. (search for that in workspace). Regular scripts cannot use UserInputService