Hello SH, ive got some trouble with a sprinting script help would be appriciated. the problem is that both functions execute inside of function onKeyPress. ive tried to prevent it and even done some debugging but i cant figure out how to prevent it.
--Variables player = script.Parent.Parent.Character sprinting = false stamina = 100 maxstamina = 100 devisionvalue = script.Parent.Parent.PlayerGui.Bars.HpBarFrame.dv.Value SBar = script.Parent.Parent.PlayerGui.Bars.HpBarFrame.StaminaBar Sl = script.Parent.Parent.PlayerGui.Bars.HpBarFrame.StaminaText
--Functions function start() --Stamina Bar SBar.Size = UDim2.new(stamina / devisionvalue,0,0, 20)
--Stamina Bar Label Sl.Text = "Stamina: " .. stamina .. "/" .. maxstamina
end
start()
function onKeyPress(actionName, userInputState, inputObject)
if sprinting == false then player.Humanoid.WalkSpeed = 40 sprinting = true stamina = stamina -5 print("executed1") redraw() return end if sprinting == true then player.Humanoid.WalkSpeed = 16 sprinting = false print("executed2") redraw() return end
end
function redraw() --Stamina Bar SBar.Size = UDim2.new(stamina / devisionvalue,0,0, 20)
--Stamina Bar Label Sl.Text = "Stamina: " .. stamina .. "/" .. maxstamina
end
--Hooks game.ContextActionService:BindAction("keyPress", onKeyPress, false, Enum.KeyCode.LeftShift)
Thanks, ScrappyHaxor