The script doesn't work

I want to make a script to run when pressing the “Shift” key. however, nothing happens. Can you help?
image

I suggest you use the following for scripts like these: UserInputService | Documentation - Roblox Creator Hub

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(input)
    Enum.KeyCode <-- Find all the keycodes including shift here 
    if input.KeyCode == Enum.KeyCode.E then
        print("I pressed E")
    end
end)

GetMouse returns Mouse which does not have KeyDown nor KeyUp events.

Use the UserInputService as suggested ^ or at least hook up the correct service/events :slight_smile:

I bet you are new or don’t know how to script.
Use UserInputService instead of Mouse cuz it’s deprecated and Enum.KeyCode instead of text to know exact button name without searching for it, also you need to check if player is died or not to avoid errors, also you need to type WalkSpeed, not Walkspeed.
If you still wanna use text you need to change LShift to LeftShift
Fixed script here:

local UserInputService = game:GetService("UserInputService")
local PlayersService = game:GetService("Players")
local Player = PlayersService.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait() --gonna equal to character, but if character is not added yet or character died it gonna wait until character gonna fully spawn
local Humanoid = Character:WaitForChild("Humanoid")
UserInputService.InputBegan:Connect(function(input,gameIsNotInProcess)
     if gameIsNotInProcess then return end
       if input.KeyCode == Enum.KeyCode.LeftShift then
           Humanoid.WalkSpeed = 100
             end
end)
UserInputService.InputEnded:Connect(function(input,gameIsNotInProcess)
     if gameIsNotInProcess then return end
       if input.KeyCode == Enum.KeyCode.LeftShift then
           Humanoid.WalkSpeed = 16
        end
end)

You have to use a local script in starter character scripts.

It doesn’t have to be in StarterCharacterScripts, and that’s definitely not the issue here.

The Mouse object isn’t used for keypresses, use UserInputService instead. Pretty sure others in this thread have already given code that works

It has to be a local script. I never said that the mouse object isn’t wrong. I was just saying how UIS has to be used in a local script and it should be put in starterCharacterScripts so it doesn’t break when the player dies.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.