How can i make a Sprint script with a smooth fov changer and stamina

Hello i was trying to make a Sprint script with an fov changer and stamina but i cant manage to achieve it since whenever i use an fov changer its not as smooth as i would like it to be Does anyone know how to make it?

Can you show what you’ve attempted already?

oh sorry i found the solution already ;-;

but here it is could you help me add the stamina i dont really know how to do that
1st code

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local sprintScript = script.SprintScript:Clone()
		sprintScript.Parent = player.Character
		sprintScript.Disabled = false
	end)
end)

2nd

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local UIS = game:GetService("UserInputService")
local tweenService = game:GetService("TweenService")


UIS.InputBegan:Connect(function(input, isTyping)
	if isTyping then return end
	
	local leftShiftInput = input.KeyCode == Enum.KeyCode.LeftShift
	local wKeyInput = input.KeyCode == Enum.KeyCode.W
	local aKeyInput = input.KeyCode == Enum.KeyCode.A
	local sKeyInput = input.KeyCode == Enum.KeyCode.S
	local dKeyInput = input.KeyCode == Enum.KeyCode.D
	
	local leftShift = UIS:IsKeyDown(Enum.KeyCode.LeftShift)
	local wKey = UIS:IsKeyDown(Enum.KeyCode.W)
	local aKey = UIS:IsKeyDown(Enum.KeyCode.A)
	local sKey = UIS:IsKeyDown(Enum.KeyCode.S)
	local dKey = UIS:IsKeyDown(Enum.KeyCode.D)
	
	if leftShiftInput or wKeyInput or aKeyInput or sKeyInput or dKeyInput then
		if wKey == true or aKey == true or sKey == true or dKey == true then
			if leftShift == true and humanoid.WalkSpeed ~= 30 then
				local info = TweenInfo.new(0.35284, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
				local goals = {FieldOfView = 80}
				local camFOVTween = tweenService:Create(workspace.CurrentCamera, info, goals)
				wait()
				camFOVTween:Play()
				
				humanoid.WalkSpeed = 18
			end
		end
	end	
end)


UIS.InputEnded:Connect(function(input, isTyping)
	if isTyping then return end
	
	local leftShiftInput = input.KeyCode == Enum.KeyCode.LeftShift
	local wKeyInput = input.KeyCode == Enum.KeyCode.W
	local aKeyInput = input.KeyCode == Enum.KeyCode.A
	local sKeyInput = input.KeyCode == Enum.KeyCode.S
	local dKeyInput = input.KeyCode == Enum.KeyCode.D
	
	local leftShift = UIS:IsKeyDown(Enum.KeyCode.LeftShift)
	local wKey = UIS:IsKeyDown(Enum.KeyCode.W)
	local aKey = UIS:IsKeyDown(Enum.KeyCode.A)
	local sKey = UIS:IsKeyDown(Enum.KeyCode.S)
	local dKey = UIS:IsKeyDown(Enum.KeyCode.D)
	
	if leftShiftInput then
		if humanoid.WalkSpeed ~= 10 then
			local info = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
			local goals = {FieldOfView = 70}
			local camFOVTween = tweenService:Create(workspace.CurrentCamera, info, goals)
			wait()
			camFOVTween:Play()
			
			humanoid.WalkSpeed = 10
		end
		
	elseif wKeyInput or aKeyInput or sKeyInput or dKeyInput then
		if wKey == false and aKey == false and sKey == false and dKey == false and humanoid.WalkSpeed ~= 10 then
			local info = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
			local goals = {FieldOfView = 70}
			local camFOVTween = tweenService:Create(workspace.CurrentCamera, info, goals)
			wait()
			camFOVTween:Play()

			humanoid.WalkSpeed = 10
		end
	end
end)

For stamina you can store the stamina value in a variable and lower the value when the player is running. If the player isn’t running, increase that value. If the stamina reaches zero, stop the player from running until they have stamina again.

Thanks! i will make this the solution!

1 Like

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