Can many loops lag the server?

so i want to have scripts check things but i have a problem, i don’t know if simple loops like this:

while task.wait(3) do
--here the script sees if a value is true or false or if the value is 10 or like 5
--here is where the script changes a textlabels text if its a certain value
end

lag the game when theres multiple scripts suddenly running every 3 seconds
i hope someone can help since idk if lag spikes in my game are coming from these loops
also should i just use

valuename.Changed:Connect(function() --i dont remember if its :Changed or that
--code here
end)

yes, always use events when you can.

Running non-intensive code every 3 seconds won’t cause issues though.


this is correct

Hey, you should use something like this;


local value = ValueName

value:GetPropertyChangedSignal("Value"):Connect(function()

if (value.Value == '10') {
// do whatever.
}

end)

The .Changed would work too for OP, but that would fire everytime a property on it is changed, if it’s just a StringValue then it’s fine but probably best to use GetPropertyChangedSignal

.Changed behavior works differently for ValueBase

2 Likes

Oh wow, I didn’t know that for Value’s - I guess I learned something new too. Thank you haha, I’m sorry!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.