I get the error ServerScriptService.Stamina:12: attempt to index nil with 'StaminaChanged'
when trying to run my code
local staminaBar = game.ServerStorage.CharacterBar.MainStamina.StaminaBar
local staminaText = game.ServerStorage.CharacterBar.MainStamina.staminaText
local maxStamina = 100
local stamina = 100
local human = game.Players.LocalPlayer
staminaBar:TweenSize(UDim2.new(stamina/maxStamina, 0, staminaBar.Size.Y.Scale, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.1, false)
staminaText.Text = stamina .. "/" .. maxStamina
human.StaminaChanged:Connect(function(currentStamina)
maxStamina = human.MaxStamina
staminaBar:TweenSize(UDim2.new(currentStamina/maxStamina, 0, staminaBar.Size.Y.Scale, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.1, false)
staminaText.Text = math.round(currentStamina) .. "/" .. maxStamina
end)
(which is a serverscript in serverscriptservice) though the script sets the stamina bar to 100/100
-
What do you want to achieve? I’d like to create a player event called StaminaChanged
-
What solutions have you tried so far? I tried making a ModuleScript in ServerScriptService for StaminaChanged but I couldn’t get that to work.