Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does this script take away 20 rather than 10? [Solved]

Asked by 5 years ago
Edited 5 years ago

When I jump my stamina bar goes down 10 the first jump, but every jump after the first it goes down 20 per jump. All the health stuff works, I only have issues with stamina.

Here is my code (local script):

--Variables
local playerName = game.Players.LocalPlayer.Name
local humanoid = game.Workspace:WaitForChild(playerName):WaitForChild("Humanoid")
local healthBar = script.Parent.main.Health.barFrame.bar
local staminaBar = script.Parent.main.Stamina.barFrame.bar
local stamCount = 100
local stamCountMax = 100

--Functions
local function update()
    local healthDecimal = humanoid.Health / humanoid.MaxHealth
    healthBar:TweenSize(UDim2.new(healthDecimal, 0, 1, 0))
end

humanoid.Jumping:Connect(function(isActive)
    if stamCount > 0 then
        stamCount = stamCount - 10
        local stamDecimal = stamCount / stamCountMax 
        staminaBar:TweenSize(UDim2.new(stamDecimal, 0, 1, 0), "In", "Linear", 0.05)
    end
end)


--Connects
humanoid.Changed:connect(update)

0
Jumping fires again shortly when it stops jumping. User#19524 175 — 5y

Answer this question