I've created a simple stamina bar with a simple script, it is not done yet but the problem is the value is not changing.

Variables

local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character.Humanoid
local over = script.Parent.Overlay
local under = script.Parent
local stamina = 100
local maxStamina = 100
local humanoidJump = false

-- Functions

function update()
	local staminaScale = stamina / maxStamina
	over:TweenSize(UDim2.new(staminaScale,0,1,0), "In", "Linear", 0.1)
	wait(0.1)
	print("Test")
end

-- Code Execution

if stamina < 100 then
	update()
end

if humanoidJump == true then --This area is where the stamina changes
	print("Test")
	stamina = 25 - stamina
elseif humanoidJump == false and stamina < 100 then
	stamina = 10 + stamina
end

game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.Space then
        humanoidJump = true --This area seemed to contain the problem
	wait(0.5)
	humanoidJump = false
	print("test")
    end 
end)

2 comments

0

Lines 23-32 will only run once when the server initiates. Try putting that part of code inside a while loop. Don't forget a wait()

0

I'll try that out, thanks for your recommendation.