#Need help with action

1 messages · Page 1 of 1 (latest)

smoky moon
#

I am trying to make it so when i hold down shift i run, i would search up a video but i want to be kinda independent but, i am completely lost, can someone give some help

delicate burrow
#

You need to use UserInputService or ContextActionService I think works too

#

That's for the input handling

#

You'd also need to get the Character with variables

#

then you'd also have to check when the shift is let go with UserInputService

smoky moon
#

could i have a example, im new and dont really understand

delicate burrow
#

Ye I gotchu

smoky moon
#

also could you like write notes that i can use for anything else if thats okay?

delicate burrow
#

mb i went afk but here u go lol

#
--// Services
local userInputService = game:GetService("UserInputService") -- getting the input service to use within the localscript
local players = game:GetService("Players")

--// Variables
local player: Player = players.LocalPlayer -- getting the local player (the client) from the players service
local character = player.Character or player.CharacterAdded:Wait() -- Getting the character from the player and if the character hasn't loaded then it's gonna wait for it to load
local humanoid = character:FindFirstChild("Humanoid") -- getting the humanoid from the character

local sprinting = false -- keeping track of if the player is sprinting already

local inputHandling = function(input: InputObject, gameProcessing: boolean)
    if gameProcessing or input.KeyCode ~= Enum.KeyCode.LeftShift then return end -- If the player is in the typing window or if the input isnt the left shift or player is already sprinting
    
    sprinting = not sprinting
    humanoid.WalkSpeed = sprinting and 24 or 16 -- increase the speed by 8 if sprinting is true
end

--// Connections
userInputService.InputBegan:Connect(inputHandling)
userInputService.InputEnded:Connect(inputHandling)

Idk why I just wrote the entire script but I did try to explain everything hope you can understand and can turn this into your own script :)