--Services--
local CAS = game:GetService("ContextActionService")
local RNS = game:GetService("RunService")
--Setting--
local staminaUsage = 0.5
local rechargeTime = 1
--Script--
local character =script.Parent
local humanoid = character:WaitForChild("Humanoid")
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local lastSprint = math.huge
local isSprinting = false
local function sprint(actionName , inputState , inputType)
if inputState == Enum.UserInputState.Begin then
isSprinting = true
elseif inputState == Enum.UserInputState.End then
isSprinting = false
end
if isSprinting then
humanoid.WalkSpeed = humanoid:GetAttribute("SprintSpeed")
else
humanoid.WalkSpeed = humanoid:GetAttribute("BaseWalkSpeed")
end
end
CAS:BindAction("Sprint", sprint,true,Enum.KeyCode.LeftShift)
RNS.RenderStepped:Connect(function(delta)
local stamina = humanoid:GetAttribute("Stamina")
if stamina < staminaUsage then
isSprinting = false
humanoid.WalkSpeed = humanoid:GetAttribute("BaseWalkSpeed")
end
if isSprinting and stamina > 0 and humanoid.MoveDirection.Magnitude > 0 then
humanoid:SetAttribute("Stamina" , stamina - staminaUsage)
lastSprint = tick()
else
if tick() - lastSprint>= rechargeTime and stamina< humanoid:GetAttribute("MaxStamina") then
humanoid:SetAttribute("Stamina" , stamina + staminaUsage)
end
end
UserInputService.InputBegan:Connect(function(input,gameProcessedEvent)
if UserInputService:IsKeyDown(Enum.KeyCode.LeftShift) then
for i = 1 , 0 , -0.1 do
wait(0.1)
player.PlayerGui.StaminaScreen.StaminaBar.BackgroundTransparency = i
player.PlayerGui.StaminaScreen.StaminaBar.Remaining.BackgroundTransparency = i
player.PlayerGui.StaminaScreen.StaminaBar.ImageLabel.ImageTransparency = i
end
end
end)
repeat wait()
until stamina == 100
UserInputService.InputBegan:Connect(function(input,gameProcessedEvent)
if UserInputService:IsKeyDown(Enum.KeyCode.LeftShift) then
for i = 1 , 0 , -0.1 do
wait(0.1)
player.PlayerGui.StaminaScreen.StaminaBar.BackgroundTransparency = i
player.PlayerGui.StaminaScreen.StaminaBar.Remaining.BackgroundTransparency = i
player.PlayerGui.StaminaScreen.StaminaBar.ImageLabel.ImageTransparency = i
end
end
end)
end)
I want to make a sprint system when we hold left shift the sprint bar will fade in and it will fade out until the sprint bar is full