#stamina jumping system wont work

106 messages · Page 1 of 1 (latest)

mint grove
#
local isJumping = false
local Stamina = script.Parent:WaitForChild("Stamina")
local MaxStamina = script.Parent:WaitForChild("MaxStamina")

local Players = game:GetService("Players")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

humanoid.StateChanged:Connect(function(oldState, newState)
    if newState == Enum.HumanoidStateType.Jumping then
        isJumping = true
        Stamina = Stamina - 20
        Stamina = math.clamp(Stamina, 0, 100)
    elseif newState == Enum.HumanoidStateType.Landed then
        isJumping = false
    end
    while task.wait(.05) do
        Stamina = Stamina + .5
        Stamina = math.clamp(Stamina, 0, 100)
        
    end
end)
broken totem
#

Did you put a infinite loop in a connect event?

hollow orbit
#

@mint grove The issue with your stamina jumping system is that you are trying to subtract and update the Stamina variable directly from the Stamina object which is not allowed You should instead update the Value property of the Stamina object

#

**local isJumping = false
local Stamina = script.Parent:WaitForChild("Stamina").Value
local MaxStamina = script.Parent:WaitForChild("MaxStamina").Value

local Players = game:GetService("Players")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

humanoid.StateChanged:Connect(function(oldState, newState)
if newState == Enum.HumanoidStateType.Jumping then
isJumping = true
Stamina = Stamina - 20
Stamina = math.clamp(Stamina, 0, MaxStamina)
elseif newState == Enum.HumanoidStateType.Landed then
isJumping = false
end
end)

while true do
if not isJumping then
Stamina = Stamina + 0.5
Stamina = math.clamp(Stamina, 0, MaxStamina)
end
wait(0.05)
end**

mint grove
#

@hollow orbit i see

#

alright

hollow orbit
#

here i fix it

mint grove
#

@hollow orbit thanks lol, i was completley redoing it before you said it xd

#

you saved me like an hour lol

hollow orbit
#

lol

#

test se if it works

mint grove
#

oh and btw if you want to make it show up in the coding format do

#

lua code

#

a

#

that didnt work

#

hold on

#

do three of these

#

`

#

then lua

#

then press enter

#

and 3 of these

#

`

hollow orbit
#
local Stamina = script.Parent:WaitForChild("Stamina").Value
local MaxStamina = script.Parent:WaitForChild("MaxStamina").Value

local Players = game:GetService("Players")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

humanoid.StateChanged:Connect(function(oldState, newState)
    if newState == Enum.HumanoidStateType.Jumping then
        isJumping = true
        Stamina = Stamina - 20
        Stamina = math.clamp(Stamina, 0, MaxStamina)
    elseif newState == Enum.HumanoidStateType.Landed then
        isJumping = false
    end
end)

while true do
    if not isJumping then
        Stamina = Stamina + 0.5
        Stamina = math.clamp(Stamina, 0, MaxStamina)
    end
    wait(0.05)
end```
mint grove
#

not quite

hollow orbit
#

any error?

mint grove
#

lets see

#

isnt working

#

the value isnt going down

hollow orbit
#

let me see

mint grove
#

the numbervalue stays at 100

#

should i send a screenshot?

hollow orbit
#
local Stamina = script.Parent:WaitForChild("Stamina")
local MaxStamina script =.Parent:WaitForChild("MaxStamina")

local Players = game:GetService("Players")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

humanoid.StateChanged:Connect(function(oldState, newState)
    if newState == Enum.HumanoidStateType.Jumping then
        isJumping = true
        Stamina.Value = Stamina.Value - 20
        Stamina.Value = math.clamp(Stamina.Value, 0, MaxStamina.Value)
    elseif newState == Enum.HumanoidStateType.Landed then
        isJumping = false
    end
end)

while true do
    if not isJumping then
        Stamina.Value = Stamina.Value + 0.5
        Stamina.Value = math.clamp(Stamina.Value, 0, MaxStamina.Value)
    end
    wait(0.05)
end```
#

try this

#
local Stamina = script.Parent:WaitForChild("Stamina").Value
local MaxStamina = script.Parent:WaitForChild("MaxStamina").Value

local Players = game:GetService("Players")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

humanoid.StateChanged:Connect(function(oldState, newState)
    if newState == Enum.HumanoidStateType.Jumping then
        isJumping = true
        Stamina = Stamina - 20
        Stamina = math.clamp(Stamina, 0, MaxStamina)
    elseif newState == Enum.HumanoidStateType.Landed then
        isJumping = false
    end
end)

while true do
    if not isJumping then
        Stamina = Stamina + 0.5
        Stamina = math.clamp(Stamina, 0, MaxStamina)
    end
    script.Parent.Stamina.Value = Stamina
    wait(0.05)
end```
mint grove
hollow orbit
#

or this

mint grove
#

am i looking in the right place

hollow orbit
#

ye

mint grove
#

yeah it isnt going down

#

hmm

hollow orbit
#

try the scripts i sent

mint grove
#

i have

#

value still isnt going down

hollow orbit
#

any errors??

mint grove
#

no

hollow orbit
#

weird

#

idk man

mint grove
#

@hollow orbit should i try completley redoing it

hollow orbit
#

try to fix it if u cant then redo

mint grove
#

@hollow orbit what do you think is going on

#

wait hold on

#

may have found the problem

#

@hollow orbit i dont even think it is being linked with the value

hollow orbit
#

maybe

mint grove
#

lemme send a screenshot

#

read the script

#

ill send the values sheet

#
local v1 = Instance.new("NumberValue",script.Parent)
v1.Name = "Oxygen"
v1.Value = 100
local v2 = Instance.new("NumberValue",script.Parent)
v2.Name = "MaxAir"
v2.Value = 100
local v2 = Instance.new("BoolValue",script.Parent)
v2.Name = "InBuilding"
v2.Value = false
local v3 = Instance.new("NumberValue",script.Parent)
v3.Name = "Stamina"
v3.Value = 100
local v3 = Instance.new("NumberValue",script.Parent)
v3.Name = "MaxStamina"
v3.Value = 100

#

@hollow orbit does it look the like script is calling itself and not the value

#

i think i have to get the values directly from the player

#

also forget the first 3 values in the values sheet

hollow orbit
#

my brain i not braining

#

idk whats the problem

mint grove
#

so

#

in the script

#
local isJumping = false
local Stamina = script.Parent:WaitForChild("Stamina").Value
local MaxStamina = script.Parent:WaitForChild("MaxStamina").Value

local Players = game:GetService("Players")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

humanoid.StateChanged:Connect(function(oldState, newState)
    if newState == Enum.HumanoidStateType.Jumping then
        isJumping = true
        Stamina = Stamina - 20
        Stamina = math.clamp(Stamina, 0, MaxStamina)
    elseif newState == Enum.HumanoidStateType.Landed then
        isJumping = false
    end
end)

while true do
    if not isJumping then
        Stamina = Stamina + 0.5
        Stamina = math.clamp(Stamina, 0, MaxStamina)
    end
    script.Parent.Stamina.Value = Stamina
    wait(0.05)
end
#

stamina is getting script.parent

#

and that is startercharacterscripts

#

and the waitforchild

#

is waiting for itself

#

basically to fix it i have to grab the values right from the player

#

@hollow orbit you get it now?

hollow orbit
#

ye

#

im fix it if didnt work again then idk man

mint grove
#

how can i grab it from the player

#

alr

hollow orbit
# mint grove how can i grab it from the player

local Players = game:GetService("Players")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local leaderstats = player:WaitForChild("leaderstats")
local Stamina = leaderstats:WaitForChild("Stamina").Value
local MaxStamina = leaderstats:WaitForChild("MaxStamina").Value

humanoid.StateChanged:Connect(function(oldState, newState)
    if newState == Enum.HumanoidStateType.Jumping then
        isJumping = true
        Stamina = Stamina - 20
        Stamina = math.clamp(Stamina, 0, MaxStamina)
    elseif newState == Enum.HumanoidStateType.Landed then
        isJumping = false
    end
end)

while true do
    if not isJumping then
        Stamina = Stamina + 0.5
        Stamina = math.clamp(Stamina, 0, MaxStamina)
    end
    leaderstats.Stamina.Value = Stamina
    wait(0.05)
end```






**
Make sure that you have a `leaderstats` folder in the player's data structure and that it contains the `Stamina `and `MaxStamina `values**
mint grove
#

1: this isnt a local script so player.localplayer wont work

#

2: what do you mean by i need a leaderstats fikder

hollow orbit
#

tp grab it from player

#

to*

mint grove
#

@hollow orbit may be a problem as i have an oxygen script

hollow orbit
# mint grove <@898337643014795275> may be a problem as i have an oxygen script

here this is not local


local Players = game:GetService("Players")

local function onCharacterAdded(character)
    local humanoid = character:WaitForChild("Humanoid")
    local player = Players:GetPlayerFromCharacter(character)
    
    local leaderstats = player:WaitForChild("leaderstats")
    local Stamina = leaderstats:WaitForChild("Stamina").Value
    local MaxStamina = leaderstats:WaitForChild("MaxStamina").Value
    
    humanoid.StateChanged:Connect(function(oldState, newState)
        if newState == Enum.HumanoidStateType.Jumping then
            isJumping = true
            Stamina = Stamina - 20
            Stamina = math.clamp(Stamina, 0, MaxStamina)
        elseif newState == Enum.HumanoidStateType.Landed then
            isJumping = false
        end
    end)
    
    while true do
        if not isJumping then
            Stamina = Stamina + 0.5
            Stamina = math.clamp(Stamina, 0, MaxStamina)
        end
        leaderstats.Stamina.Value = Stamina
        wait(0.05)
    end
end

Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        onCharacterAdded(character)
    end)
end)```
mint grove
#

@hollow orbit so where can i add a leaderstats folder

hollow orbit
#

local function onPlayerAdded(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player
    
    local Stamina = Instance.new("IntValue")
    Stamina.Name = "Stamina"
    Stamina.Value = 0
    Stamina.Parent = leaderstats
    
    local MaxStamina = Instance.new("IntValue")
    MaxStamina.Name = "MaxStamina"
    MaxStamina.Value = 100
    MaxStamina.Parent = leaderstats
end

Players.PlayerAdded:Connect(onPlayerAdded)```
#

this makes the folder

mint grove
#

@hollow orbit in a new script?

#

@hollow orbit also i already have a folder for values

hollow orbit
#

i dont understand man like

mint grove
#

?

hollow orbit
#

i gotta to other people im sorry i will go for now try to fix i will be back

mint grove
#

ok

#

@hollow orbit u back yet?

hollow orbit
#

see

mint grove
#

alr

#

i have a question rq

hollow orbit
#

hmm

mint grove
#
local v1 = Instance.new("NumberValue",script.Parent)
v1.Name = "Oxygen"
v1.Value = 100
local v2 = Instance.new("NumberValue",script.Parent)
v2.Name = "MaxAir"
v2.Value = 100
local v2 = Instance.new("BoolValue",script.Parent)
v2.Name = "InBuilding"
v2.Value = false
local v3 = Instance.new("NumberValue",script.Parent)
v3.Name = "Stamina"
v3.Value = 100
local v3 = Instance.new("NumberValue",script.Parent)
v3.Name = "MaxStamina"
v3.Value = 100
#

aand remove v3

hollow orbit
#

try it