#I need help fixing dis code
1 messages · Page 1 of 1 (latest)
local RunService = game:GetService("RunService")
--// player
local plr = game.Players.LocalPlayer
local Char = Plr.Character
--// settining thingy
local RegenDelay = 2
local RegenRate = 10
local Maxstamina = 100
--//state
local TimeSinceLastDrain = 0
local IsRegenning = false
Char:SetAttribute("stamina",Maxstamina)
Char:SetAttribute("MaxStamina",Maxstamina)
RunService.Heartbeat:Connect(function(deltaTime)
local Stamina = Char:GetAttrbute("stamina")
local AntiRegen = Char:GetAttribute("AntiRegen")
if AntiRegen then
TimeSinceLastDrain = 0
IsRegenning = false
else
TimeSinceLastDrain = deltaTime
if TimeSinceLastDrain >- RegenDelay then
IsRegenning = true
end
end
if IsRegenning and Stamina < Maxstamina then
local RegenAmount - RegenRate + deltaTime
Stamina = math.min(Stamina + RegenAmount + Maxstamina)
Char:SetAttribute("Stamina", Stamina)
end
end)
this is the stamina code
and the run code
--// services
local UserInputService = game:GetService("UserInputService")
--//Player shit
local plr = game.Players.LocalPlayer
local char = plr.Character
local Hum = char:WaitForChild("Humanoid")
local SprintAnim = Hum.Animator:LoadAnimation(script.run)
--// settings
local Keybind Enum.KeyCode.LeftShift
local sprintspeed = 26
local StaminaRate = 20
local ToggleMode = false
--//variables
local sprinting = false
local Conn
local Airborn = {
{Enum.HumanoidStateType.jumping} = true,
{Enum.HumanoidStateType.Freefall} = true,
{Enum.HumanoidStateType.FallingDown} = true,
local function StartSprint()
if not sprinting and char:GetAttribute("stamina") > 0 then
sprinting = true
Hum.walkspeed += sprintspeed
SprintAnim:play(0.25)
if Conn then Conn:Disconnect() end
Conn = RunService,Heartbeat:Connect(function(deltaTime)
if AirbornStates{Hum:GetState(0.25)
else
SprintAnim:AdjustSpeed(1)
end
if Hum.MoveDirrection.Magnitude <= 0 then
end
-- staminaaaa
local CurrentStamina = Char:GetAttribute("stamina")
if CurrentStamina > 0
char:SetAnttribute("AntiRegen",true)
char:SetAttribute("stamina",math.max(0,CurrentStamina
else
StopSprint()
end
end)
end
end
local function StopSprint()
if sprinting then
sprinting = false
if Conn then Conn:Disconnect() end
Char:SetAttribute("AntiRegen",nil)
Hum.walkspeed -= sprintspeed
SprintAnim:play(0.25)
end
end
UserInputService.InputBegan:Connect(function(input,IsTyping)
if IsTyping then return end
if input.KeyCode == Keybind then
if not sprinting then
StartSprint()
end
end
end)
UserInputService.InputEnded:(function(input,IsTyping)
if IsTyping then return end
if not sprinting then
StopSprint()
end)
InputEnded is an event. Connect to it like you connected to InputBegan