#need help finishing a script

49 messages · Page 1 of 1 (latest)

weak python
#
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)
#

it isn't finished

chrome linden
#

is it not working or something?

weak python
#

@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

chrome linden
weak python
#

ah

#

so

#
math.clamp(stamina, 0, 100)
#

that?

chrome linden
#

well to put it in you'd do this but yea

(yourstaminavariable) = math.clamp(stamina, 0, 100)
weak python
#

@chrome linden do i put it in the while task.wait loop

chrome linden
#

you do it every time you change the stamina

weak python
#

@chrome linden im confused

chrome linden
#
Stamina = math.clamp((Stamina + .5), 0, 100)
weak python
#

@chrome linden on where i put it

chrome linden
#

you replace all the places where you change the stamina with that

weak python
#

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

chrome linden
#

well if you're gonna do it like that just do

Stamina = math.clamp(Stamina, 0, 100)
weak python
#

where is the optimal place to put it

covert tulipBOT
#

studio** You are now Level 8! **studio

chrome linden
#

thats fine

weak python
#

so should this script work

chrome linden
#

yea should

weak python
#

@chrome linden it isnt, the value isnt going donw

#

stamina's number value is always 100

chrome linden
#
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)
weak python
#

alr

#

nope...

chrome linden
#

is it just going to 100

weak python
#

it remains at 100 even when i jump

chrome linden
#

then i think your base value was above 100

weak python
#
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

chrome linden
#

do you have any scripts that are adding to the value at all

weak python
#

no

#

this one creates the value in the player

#

the jumping script is the only one that changes it

#

the one we just saw

chrome linden
#

was it subtracting from the value before

weak python
#

no

#

wait

#

the script is in startercharacterscripts

#

does that matter

chrome linden
#

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)
chrome linden