#stamina system problem atm

8 messages · Page 1 of 1 (latest)

solemn glacier
#

i have a part in my script that tracks when my stamina goes over 40 and above 40 but the problem is when it goes above 40 i dont want it to keep replying i want to jst happen once and den stop but instead its repeating it self anyone can help?

if Stamina <= 40 and not effectApplied then
        print("Below 40 working")
        local targetTransparency = math.clamp((Stamina / 100), 0, 0.8)

        TweenService:Create(UI.Vignette, TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {ImageTransparency = targetTransparency}):Play()
        TweenService:Create(Camera, TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {FieldOfView = 60}):Play()

        StaminaBar.warning.Visible = true

        effectApplied = true
        effectReset = false
    end

    if Stamina > 40 and not effectReset then
        print("above 40 working")
        TweenService:Create(UI.Vignette, TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {ImageTransparency = 0.8}):Play()

        StaminaBar.warning.Visible = false

        effectReset = true
        effectApplied = false
    end```
woven sky
solemn glacier
#

that could be the problem but like ion have anything that says it should loop the thing is i dont want to loop above 40

#

bc it like bugs out my sprint fov keeping it active

#

i want it to kinda make it like it only works that one time going above 40 and waits for it to go back below 40

woven sky
# solemn glacier Yeah its a segment

are you defining effectReset within the call flow?

for example

local function effectsYay()
  local effectReset = false -- if this is the case, define it outside the function
  local stamina = 41
--blah blah code
  if stamina > 40 and not effectReset then
    print("blah blah code")
    effectReset = true
  end
end

effectsYay()
effectsYay()

--[[
Output is always going to be the print as you are redefining effectReset from within the function
]]
solemn glacier
#

Yea