I am adapting the following Roblox script to create a sprint code
local UserInputService = game:GetService("UserInputService")
-- Shift keys
local shiftKeyL = Enum.KeyCode.LeftShift
local shiftKeyR = Enum.KeyCode.RightShift
-- Return whether left or right shift keys are down
local function IsShiftKeyDown()
return UserInputService:IsKeyDown(shiftKeyL) or UserInputService:IsKeyDown(shiftKeyR)
end
-- Handle user input began differently depending on whether a shift key is pressed
local function Input(input, gameProcessedEvent)
if not IsShiftKeyDown() then
-- Normal input
else
-- Shift input
end
end
UserInputService.InputBegan:Connect(Input)
Above is the original code.
Below is the code I have at this moment.
local UserInputService = game:GetService("UserInputService")
-- Shift keys
local shiftKeyL = Enum.KeyCode.LeftShift
local shiftKeyR = Enum.KeyCode.RightShift
-- Return whether left or right shift keys are down
local function IsShiftKeyDown()
return UserInputService:IsKeyDown(shiftKeyL) or UserInputService:IsKeyDown(shiftKeyR) or UserInputService:IsGamepadButtonDown(Enum.KeyCode.ButtonL1)
end
-- Handle user input began differently depending on whether a shift key is pressed
local function Input(input, gameProcessedEvent)
if not IsShiftKeyDown() then
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16 -- Normal input
else
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 32 -- Shift input
end
end
UserInputService.InputBegan:Connect(Input)
And I am getting the following Output:
18:22:53.803 - Unable to cast token to token
18:22:53.805 - Stack Begin
18:22:53.805 - Script 'Workspace.IncredibleTeamAidan.Run New', Line 9 - function IsShiftKeyDown
18:22:53.806 - Script 'Workspace.IncredibleTeamAidan.Run New', Line 14 - function Input
18:22:53.807 - Stack End
It appears that the issue is with detecting the buttons pressed in lines 8 to 10
local function IsShiftKeyDown()
return UserInputService:IsKeyDown(shiftKeyL) or UserInputService:IsKeyDown(shiftKeyR) or UserInputService:IsGamepadButtonDown(Enum.KeyCode.ButtonL1)
end
however I believe it could be with line 21
UserInputService.InputBegan:Connect(Input)
If anybody knows how I may be able to adjust this to work, that would be much appreciated
Other Information:
Code is within a local script, stored in Game.StarterPlayer.StarterCharacterScripts

1 comment
Please don't take code from the ROBLOX wiki.