#My sprint animation is bugging
1 messages · Page 1 of 1 (latest)
local UserInputService = game:GetService("UserInputService")
local humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
local RunService = game:GetService("RunService")
local camera = game.Workspace.Camera
local animation = script.runAnimation
local AnimTrack = humanoid:LoadAnimation(animation)
local sprint = false
local walkSpeed = 10
local sprintSpeed = 25
local maxStamina = 1000
local stamina = maxStamina
local regenStamina = maxStamina/600
local drainSpeed = 0.25
local drained = false
local function isMoving()
local moveDirection = humanoid.MoveDirection
return moveDirection.Magnitude > 0
end
RunService.Heartbeat:Connect(function()
if sprint then
if stamina > 0 then
stamina = math.max(stamina - drainSpeed, 0)
AnimTrack:Play()
else
sprint = false
drained = true
humanoid.WalkSpeed = walkSpeed
camera.FieldOfView = 60
end
elseif not sprint then
stamina = math.min(stamina + regenStamina, maxStamina)
if drained and stamina == maxStamina then
drained = false
end
if not isMoving() then
camera.FieldOfView = 60
end
end
end)
UserInputService.InputBegan:Connect(function(Input, isTyping)
if isTyping then return end
if Input.KeyCode == Enum.KeyCode.LeftShift and not drained and isMoving() then
sprint = true
camera.FieldOfView = 55
humanoid.WalkSpeed = sprintSpeed
end
end)
UserInputService.InputEnded:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.LeftShift then
sprint = false
camera.FieldOfView = 60
humanoid.WalkSpeed = walkSpeed
end
end)
i've juste put a :Pley() one time to see the loop of the animation
but the loop didn't worl
:Pley()?
:Play() sorry
ur calling the animation every frame
only play it when sprinting is true and then stop it if sprinting ends
i try it but the result is the same
** You are now Level 1! **
did u remove the loop also?
yes
is ur anim Looped?
how so ?
ur anim is restarting every frame in heartbeat service
remove AnimTrack:Play() from heartbeat and
move it to inputbegan
yeah i've do that, there is no more AnimTrack:Play() form heartbeat but the problem is still the same
thx
if AnimTrack:IsPlaying then
AnimTrack:Stop()
at the end
and check animation properties
if looped is enabled
RunService.Heartbeat:Connect(function()
if sprint then
if stamina > 0 then
stamina = math.max(stamina - drainSpeed, 0)
else
sprint = false
drained = true
humanoid.WalkSpeed = walkSpeed
camera.FieldOfView = 60
end
elseif not sprint then
stamina = math.min(stamina + regenStamina, maxStamina)
if drained and stamina == maxStamina then
drained = false
end
if not isMoving() then
camera.FieldOfView = 60
end
end
AnimTrack:Stop()
end)
like that ?
no
IsPlaying have parentheses no ?
how ?
enabled
find ur animation
that u use
or u use
roblox one
check the run animation properties
in workspace
i've tried that and that cause my pc to crash
** You are now Level 2! **
no i don't
where ?
loop is actived
give ur animid
86305053668673
u got any errors in ur output?
okay wait
i got the animation and the script in my studio
imma try some things rq
i got the same error u hav
if i remove the runservice that doesn't work aswell
so what i think
myself
if im wrong or not
but
walk overrides the animation
imma fix it rq
and then send u the script
Thx
I have to delete the walk animation of the rig that i use in statercharacter ?
nono
dont delete anything
its simple fix
just setting the priority higher in script
give me 1 sec
okay thx
very thank you for your help mate