I'm trying to make a character sprint when you press left shift, however when I test this my character stays at normal speed. (Also sorry if the answer is super obvious I just started trying to code yesterday)
local uis = game:GetService("UserInputService") local char = game.StarterPlayer.StarterCharacter uis.InputBegan:connect(function(input) if input.KeyCode == Enum.KeyCode.LeftShift then char.Humanoid.WalkSpeed = 30 end end)
Thanks in advance
You don't appear to be doing anything that would normally wrong except for you not accounting for Experimental Mode is off, meaning anything done on client does not necessarily reach the server. I suggest you read up on Remotes so you can properly modify your script.
**First, I hope you are using a local script, if so please change line 2 into local char = game.Player.LocalPlayer.CharacterAdded:wait()
**
I suggest using a RemoteEvent, on line 6 you should replace your code with:
RemoteEvent:FireServer()
Due to your desire to sprint, you don't need to pass any arguments to pick a speed because it should be a set amount you can change on the server.
Now you need a server script with the following code:
RemoteEvent.OnServerEvent:Connect(function(Player) if Player.Character.Humanoid.Health > 0 then Player.Character.Humanoid.WalkSpeed = 30 end end
All you need to do after this point is to be sure you create a way to slow your character down when they are done sprinting and to make RemoteEvent
a variable or a directory to the RemoteEvent you are using.
If you aren't using a custom character model, this isn't the correct way to do it. This is how I would do it, assuming you aren't using a custom character.
local uis,char=game:GetService("UserInputService"),game:GetService("Players").LocalPlayer.Character uis.InputBegan:connect(function(input) if input.KeyCode == Enum.KeyCode.LeftShift then char.Humanoid.WalkSpeed = 30 end end
your code looks good, the one possible cause of this could be putting the code in server script; so if the code is in server script then put it in LocalScript and parent the LocalScript in places like starter pack,or etc. just not in any server related services like - workspace,server script service, server storage, and etc.
** so example of how you could do it in local script:**
local player = game.Players.LocalPlayer local uis = game:GetService("UserInputService") local character = player.Character uis.InputBegan:Connect(function(input) if input.KeyCode == Enum.KeyCode.LeftShift then if character then character:WaitForChild("Humanoid").WalkSpeed = 30 end end end)