I assume that your TermCap value is what the size of the progress bar should be. In this case, I’d recommend changing your local script’s code such that rather than changing the size of the bar in that while wait()
loop (which seems to be an infinite loop, by the way) you change the size by listening to the Changed
event of TermCap
. Here’s what the code could look like:
local Player = ...
local Bar = ...
local TerminalValues = game:GetService("ReplicatedStorage").TerminalValues
local TermCap = TerminalValues.TermCap
-- Setup a connection to the Changed event of TermCap
TermCap.Changed:Connect(function(value)
-- This print statement is optional. Include it to make sure this code both works and works *as expected* (no bugs)
print("Value of TermCap changed! Value currently: " .. value)
-- Set size of bar according to the new value of TermCap
Bar.Size = UDim2.new(1 / Cap.Value, 0, 1, 0)
end)
In case you are wondering, the Changed event is an event that is fired by all instances any time the value of one of their properties is changed. For example, if a Humanoid’s Health was changed, the Humanoid’s Changed event would fire. However, there is a slight difference between the Changed event of InstanceValues versus the Changed event of other Instances. For InstanceValues (NumberValues, CFrameValues, etc), the argument provided through the Changed event is the value of the InstanceValue’s Value (i.e. a NumberValue’s value changes to “3”, so Changed is fired with the number 3 as an argument) as opposed to the name of the property that was changed (if a Humanoid’s Health changed, the argument passed is the string “Health” rather than what the actual health is).
I suggest you do your connection in the way I proposed because every time the value of TermCap
is changed, your clients will receive the Changed event immediately. This also means that whenever the value of TermCap
is not changed, the client will not need to do anything. Contrast this to a constantly running while wait()
(or while true do wait()
) loop. When TermCap
isn’t changing, your while loop would still be running, which takes up unnecessary resources.
Whenever you think you need some kind of constantly running while wait()
loop, try to think if there is some kind of event you can connect (or create and then connect) to. This will free up resources for your computer (although for any events you do connect to, remember to consider disconnecting them as well if possible. I read from some post on Lua Learning that leaving your connections connected is a super easy way to take up memory and lag your game).
The code I presented does not regard times in which you do not need to deal with the progress bar (i.e. showing the raid progress is not necessary). If this is true in a way such that the progress bar only needs to be dealt with whenever the RaidClient
event is received, then you can consider doing one of the following:
- Make a boolean variable that dictates when it is necessary to change the size of the bar. Wrap the
Bar.Size = ...
part of the code in an if statement that only lets that line of code run when the boolean variable allows it to. When the RaidClient
event is received, set the variable accordingly.
- Save memory by disconnecting the
Changed
event connection. Change it so that whenever RaidClient
is received, the connection is created in there. Store the connection in a variable. Whenever a different event is fired that informs the user that the raid has ended, disconnect the connection.
Hopefully I understood your question and situation correctly such that this post helps.