Shift to sprint script not working?

I was trying to make a shift to sprint script for my game, where you hold left shift to sprint.

When I play test the game it doesn’t work I don’t know why does anyone see any issues?

I have tried a few different ways to make this script but none of them worked.

local uis = game:GetService("UserInputService")
uis.InputBegan:Connect(function(key)
if key == Enum.KeyCode.LeftShift then
	game.Workspace.Camera.FieldOfView = 100
	script.Parent.Parent.Character.Humanoid.WalkSpeed = 20 
	uis.InputEnded:Connect(function(key2)
		if key2 == Enum.KeyCode.LeftShift then
			game.Workspace.Camera.FieldOfView = 70
			script.Parent.Parent.Character.Humanoid.WalkSpeed = 16 
		end
	end)
end

end)

Does anyone see any problems with the script? I don’t really see any problems but that might just be me.

Here is the dev log, there is no errors in her about the script, and yes it is a local script and I did put it in StarterPlayerScripts.

Change to

workspace.CurrentCamera.FieldOfView = 100

Same for when the input ends as well

1 Like

Does not work the input does not fire. That’s why this script doesn’t work, but still thank you for the help.

Try this out?

local uis = game:GetService("UserInputService")

local player = game.Players.LocalPlayer

uis.InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.LeftShift then
		game.Workspace.Camera.FieldOfView = 100
		player.Character.Humanoid.WalkSpeed = 20 
	end
end)

uis.InputEnded:Connect(function(key2)
	if key2.KeyCode == Enum.KeyCode.LeftShift then
		workspace.CurrentCamera.FieldOfView = 70
		player.Character.Humanoid.WalkSpeed = 16 
	end
end)

I think the issue may be you’re forgetting to do .KeyCode, or it’s something with the character

1 Like

This works, thank you. I will remember to put .KeyCode now.

1 Like

Anytime! If you have anymore issues don’t be afraid to make another post!

1 Like