I want "ModeText" to display the ammount of mode the player has, the mode should start with 0 and fill by 2% every 3 seconds, but it doesnt work and I dont know why. this is my gui: StarterGui > ModeBarGui (gui) > ModeBarDisplay (frame) > ModeBarScript (local script) and ModeText (text label)
this is the script located in gui:
local player = game.Players.LocalPlayer local character = player.Character or player.CharacterAdded:Wait() local humanoid = character:WaitForChild("Humanoid") local PlayerMode = script.Parent.ModeText local ModeAmount = 0 while true do ModeAmount = ModeAmount + 2 wait(3) end humanoid.ModeAmountChanged:Connect(function(FillMode) script.Parent.Size = UDim2.new(ModeAmount, 0, 1, 0) PlayerMode.Text = ModeAmount .. "%" end)
Ahh, I see a common mistake most starter coders in Roblox do: you cannot run functions or anything after a loop. Always run anything before a loop. From the word itself "loop", the script gets stuck in that loop and repeats forever until breaks it. Also, what is the maximum length of ModeBarDisplay
? If it reaches 100 it would be so long it reached outside of the screen. Also put a limit in adding ModeAmount
, else it would add forever. I assume the limit of ModeAmount is 100. You also can't make a custom event like what you did in line 12, humanoid.ModeAmounthChanged
doesn't exist and it will error. Instead, put it inside the loop.
For example, the maximum length of ModeBarDisplay is 0.8 (1 fits the length of the whole screen). For the size, you divide MoudeAmount by 100 first, then multiply it by the length limit of ModeBarDisplay.
For the PlayerMode, divide the ModeAmount by its maximum, then multiply by 100.
local player = game.Players.LocalPlayer local character = player.Character or player.CharacterAdded:Wait() local PlayerMode = script.Parent.ModeText local MaxModeBarDisplayLength = 0.8 -- example local ModeAmount = 0 local MaxModeAmount = 100 -- example while task.wait(3) do ModeAmount = ModeAmount + 2 script.Parent.Size = UDim2.new((ModeAmount/MaxModeAmount)*MaxModeBarDisplayLength, 0, 1, 0) PlayerMode.Text = (ModeAmount/MaxModeAmount)*100 .. "%" end