#my animation wont play

1 messages · Page 1 of 1 (latest)

orchid elbow
#

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local stamina = 100
local sprinting = false

local ui = player:WaitForChild("PlayerGui"):WaitForChild("StaminaGUI")
local staminaBar = ui:WaitForChild("StaminaBackground"):WaitForChild("StaminaBar")

-- Animation setup
local runAnimation = Instance.new("Animation")
runAnimation.AnimationId = "rbxassetid://73858520844992" -- Replace with your animation asset ID
local runTrack = nil

local function startSprint()
if stamina > 10 then
humanoid.WalkSpeed = 24
sprinting = true
-- Play running animation
if not runTrack then
runTrack = humanoid:LoadAnimation(runAnimation)
end
if runTrack and not runTrack.IsPlaying then
runTrack:Play()
end
end
end

local function stopSprint()
humanoid.WalkSpeed = 16
sprinting = false
-- Stop running animation
if runTrack and runTrack.IsPlaying then
runTrack:Stop()
end
end

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input, processed)
if processed then return end
if input.KeyCode == Enum.KeyCode.LeftShift then
startSprint()
end
end)

UIS.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
stopSprint()
end
end)

game:GetService("RunService").RenderStepped:Connect(function()
if sprinting and stamina > 0 then
stamina = stamina - 0.5
elseif not sprinting and stamina < 100 then
stamina = stamina + 0.25
end

if stamina <= 0 then
    stopSprint()
end

staminaBar:TweenSize(UDim2.new(1, 0, stamina / 100, 0), "Out", "Quad", 0.2, true)

end)