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
elseif newState == Enum.HumanoidStateType.Landed then
isJumping = false
end
while task.wait(.05) do
Stamina = Stamina + .5
if Stamina >= MaxStamina then
end
end
end)
#need help finishing a script
49 messages · Page 1 of 1 (latest)
is it not working or something?
@chrome linden i need help finishing it, and i feel like I have made a lot of mistakes
like i need to make sure stamina doesnt go above 100
im new to this, so i am certain i am making zillions of mistakes
ok easy way to do that is math.clamp
math.clamp(x, min, max) --x is what you are clamping to the min and max
well to put it in you'd do this but yea
(yourstaminavariable) = math.clamp(stamina, 0, 100)
@chrome linden do i put it in the while task.wait loop
you do it every time you change the stamina
@chrome linden im confused
Stamina = math.clamp((Stamina + .5), 0, 100)
@chrome linden on where i put it
you replace all the places where you change the stamina with that
ill edit the script and tell me if its correct
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
elseif newState == Enum.HumanoidStateType.Landed then
isJumping = false
end
Stamina = math.clamp((Stamina + .5), 0, 100)
end)
i think thats good
well if you're gonna do it like that just do
Stamina = math.clamp(Stamina, 0, 100)
where is the optimal place to put it
** You are now Level 8! **
thats fine
so should this script work
yea should
@chrome linden it isnt, the value isnt going donw
stamina's number value is always 100
ocal 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)
if Stamina >= MaxStamina then
end
end
end)
is it just going to 100
it remains at 100 even when i jump
then i think your base value was above 100
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
nope
do you have any scripts that are adding to the value at all
no
this one creates the value in the player
the jumping script is the only one that changes it
the one we just saw
was it subtracting from the value before
i gtg but try smth like this
ocal 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)
(directoryForTheNumberValue).Value = Stamina
elseif newState == Enum.HumanoidStateType.Landed then
isJumping = false
end
while task.wait(.05) do
Stamina = Stamina + .5
Stamina = math.clamp(Stamina, 0, 100)
(directoryForTheNumberValue).Value = Stamina
if Stamina >= MaxStamina then
end
end
end)
shouldn't