Artificial Intelligence
Please fill the required field.

local walkSpeed = 40 -- Change this number to your preferred speed local jumpPower = 50 -- Access the local player's character and humanoid local player = game.Players.LocalPlayer local character = player.Character or player.CharacterAdded:Wait()


To modify your existing script so that the player's walk speed and jump power are only activated while the Shift key is pressed, you'll want to incorporate input handling using the `UserInputService`. Here's an updated version of your script that implements this functionality: ```lua local UserInputService = game:GetService("UserInputService") local walkSpeed = 40 -- Change this number to your preferred speed local jumpPower = 50 -- Access the local player's character and humanoid local player = game.Players.LocalPlayer local character = player.Character or player.CharacterAdded:Wait() local humanoid = character:WaitForChild("Humanoid") -- Function to update humanoid properties local function updateHumanoidProperties() humanoid.WalkSpeed = walkSpeed humanoid.JumpPower = jumpPower end -- Set the initial properties updateHumanoidProperties() -- Optional: Ensure walk speed persists after respawn player.CharacterAdded:Connect(function(char) character = char humanoid = character:WaitForChild("Humanoid") updateHumanoidProperties() end) local shifting = false local function onInputBegan(input, gameProcessedEvent) if input.UserInputType == Enum.UserInputType.Keyboard and input.KeyCode == Enum.KeyCode.LeftShift then shifting = true updateHumanoidProperties() -- Apply the properties when shift is pressed end end local function onInputEnded(input, gameProcessedEvent) if input.UserInputType == Enum.UserInputType.Keyboard and input.KeyCode == Enum.KeyCode.LeftShift then shifting = false humanoid.WalkSpeed = 16 -- Reset to default walk speed humanoid.JumpPower = 50 -- Reset to default jump power (change as needed) end end -- Connect input events UserInputService.InputBegan:Connect(onInputBegan) UserInputService.InputEnded:Connect(onInputEnded) ``` ### Explanation: 1. **UserInputService**: This service allows you to handle user input events like keyboard presses. 2. **Shift Key Handling**: The script listens for when the Shift key is pressed (`InputBegan`) and released (`InputEnded`). 3. **Updating Character Properties**: The `updateHumanoidProperties` function sets the WalkSpeed and JumpPower. It's called to apply settings when the character spawns and whenever the Shift key is pressed. 4. **Resetting Properties**: When the Shift key is released, the script resets the properties back to the default values (In this case, walk speed is set to 16, which is Roblox's default). You can adjust this value as needed. Make sure to test the script in a local environment to ensure proper input handling and functionality.