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

I'm using while i do but then it won't work, and has no errors how to fix?

Asked by 7 years ago

Here's my script;

local player = game.Players.LocalPlayer
local staminabar = script.Parent:WaitForChild("StaminaBar")
local staminatext = script.Parent.StaminaBar:WaitForChild("StaminaText")

player.CharacterAdded:connect(function()
    local currentstamina = player:WaitForChild("Status"):WaitForChild("CurrentStamina")
    local maxstamina = player:WaitForChild("Status"):WaitForChild("MaxStamina")
    staminatext.Text = "Stamina: "..currentstamina.Value.." / "..maxstamina.Value
end)

player.CharacterAdded:connect(function()
    local currentstamina = player:WaitForChild("Status"):WaitForChild("CurrentStamina")
    local maxstamina = player:WaitForChild("Status"):WaitForChild("MaxStamina")
    currentstamina.Changed:connect(function(Value)
        local staminapercentage = currentstamina.Value / maxstamina,Value
        staminabar.Size = UDim2.new(staminapercentage, 0, 1, 0)
        staminatext.Text = "Stamina: "..currentstamina.Value.." / "..maxstamina.Value
            while i <= maxstamina.Value do
             i = currentstamina.Value + 1
            wait(1)
        end
    end)
end)

There are no errors,

This is the place that doesn't work;

            while i <= maxstamina.Value do
             i = currentstamina.Value + 1
            wait(1)
        end

Please help.

0
Are you sure the CharacterAdded functions trigger? RubenKan 3615 — 7y
0
isn't character added when you join? BlackOrange3343 2676 — 7y
0
CharacterAdded doesn't work when you use it in a localscript the first time, as the script will get loaded after the character gets added RubenKan 3615 — 7y

Answer this question