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)
#stamina jumping system wont work
106 messages · Page 1 of 1 (latest)
Did you put a infinite loop in a connect event?
@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").Valuelocal 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**
here i fix it
@hollow orbit thanks lol, i was completley redoing it before you said it xd
you saved me like an hour lol
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
`
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```
not quite
any error?
let me see
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```
or this
am i looking in the right place
ye
ill try this
try the scripts i sent
any errors??
no
@hollow orbit should i try completley redoing it
try to fix it if u cant then redo
@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
maybe
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
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?
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**
two things
1: this isnt a local script so player.localplayer wont work
2: what do you mean by i need a leaderstats fikder
@hollow orbit 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)```
@hollow orbit so where can i add a leaderstats folder
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
i dont understand man like
?
i gotta to other people im sorry i will go for now try to fix i will be back
hmm
can i put this in my values script
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
try it