#running without animation
1 messages · Page 1 of 1 (latest)
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local MAX_STAMINA = 10
local COOLDOWN_TIME = 5
local SPRINT_SPEED = 32
local DEFAULT_SPEED = 16
local STAMINA_DRAIN_RATE = 1 -- per second
local STAMINA_RECOVERY_RATE = 0.5 -- per second
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local CurrentStamina = MAX_STAMINA
local Sprinting = false
local InCooldown = false
local function UpdateSpeed()
if Sprinting and not InCooldown and CurrentStamina > 0 then
Humanoid.WalkSpeed = SPRINT_SPEED
else
Humanoid.WalkSpeed = DEFAULT_SPEED
end
end
local function StartCooldown()
InCooldown = true
Sprinting = false
UpdateSpeed()
task.delay(COOLDOWN_TIME, function()
InCooldown = false
end)
end
local function onInputBegan(Input, gameProcessed)
if gameProcessed then return end
if Input.KeyCode == Enum.KeyCode.LeftShift and not InCooldown then
Sprinting = true
UpdateSpeed()
end
end
local function onInputEnded(Input, gameProcessed)
if gameProcessed then return end
if Input.KeyCode == Enum.KeyCode.LeftShift then
Sprinting = false
UpdateSpeed()
end
end
RunService.RenderStepped:Connect(function(dt)
if Sprinting and not InCooldown then
CurrentStamina -= STAMINA_DRAIN_RATE * dt
if CurrentStamina <= 0 then
CurrentStamina = 0
StartCooldown()
end
elseif not Sprinting and not InCooldown and CurrentStamina < MAX_STAMINA then
CurrentStamina += STAMINA_RECOVERY_RATE * dt
if CurrentStamina > MAX_STAMINA then
CurrentStamina = MAX_STAMINA
end
end
end)
UserInputService.InputBegan:Connect(onInputBegan)
UserInputService.InputEnded:Connect(onInputEnded)
You need to load the animation on the humanoid and then play it
define the animation object then you can do something like this
local Anim = -- Your anim
local Humanoid = Character.Humanoid
local RunningAnimTrack = Humanoid.Animator:LoadAnimation(Anim)
-- Now you can start/ stop the animation accordingly using these methods
RunningAnimTrack:Play()
RunningAnimTrack:Stop()
of course you want to bind the start and stop to the start and stop of your sprint
wdym?
What part
** You are now Level 5! **
You already have the animation so upload it and reference it in your code
i didn't understanded anything you said ;-;