#need help with a sprinting mechanic
1 messages · Page 1 of 1 (latest)
so it keeps sprinting even when the bar is empty?
** You are now Level 2! **
yea
but only if i keep holding the shift key down
you need to make sure that sprinting is set to false immediately when the bar is empty, and also block startSprinting() from being called again until the cooldown is over, even if the sprint key is still held
so just replace your startSprinting function with this:
local function startSprinting()
if not sprinting and sprintBarPercent > 0 and not cooldown then
sprinting = true
humanoid.WalkSpeed = sprintSpeed
SprintEvent:FireServer(true)
sprintBar.Visible = true
-- Run in a separate thread so we don't block other code
coroutine.wrap(function()
while sprinting and sprintBarPercent > 0 do
sprintBarPercent -= 0.02
updateSprintBar(sprintBarPercent)
task.wait(0.1)
end
if sprintBarPercent <= 0 then
stopSprinting() -- Stop immediately once depleted
end
end)()
end
end
ok
its working
** You are now Level 1! **