So, I’m making a script that makes the Wi-Fi bar go up and down like its searching for Wi-Fi, but for some reason it’s not wanting to change the icon to no Wi-Fi, low Wi-Fi, and mid Wi-Fi, and full Wi-Fi. It’s for a bodycam and I’ve been wanting to make it look as active as possible if that makes since.
Yes, I know it’s very bad organization but it gets the job done, but here is the code and the starterGui/The place all of the stuff is in. I’m hoping there is a way I can fix this or if any of you guys can fix this. Thanks for all feedback, or solutions on how to fix what’s going wrong. (P.S I Know this is very basic looping I’m kind of new to loops in general and scripting I’ve only been scripting for about a year now but I’m making very slow progress for some reason)
I’d recommend changing the script up a bit as it seems repetitive, if you’d like help with that let me know. However your exact issue is because you’re running this as a Script, rather than a LocalScript. Try this in a LocalScript and this should work.
That would be awesome if you could help me with the repetitiveness. I’m new to scripting like I said and I’m a bit bad at the whole scripting optimization things. And thank you it did work as a local script
While you change UI elements it is best to do it from a LocalScript since it is ran from the client and gives the most synchronized experience for the player. While you can change GUI values from a server script it at times can give undesired results.
To decrease repetition you should first pan out and ask yourself “What is this doing?”
In context; you are using a “repeat until” loop to make it appear like an image is animated, however the way you are doing it in itself is inefficient. You are using multiple image instances, when you could be using one, for example. Instead of having all of those ImageLabel’s you could use one, and change the “Image” property to reflect your desired result.
Here is a rough example;
local wifiImage = script.Parent.WifiImage
local T = true
repeat
wifiImage.Image = "rbxassetid://IMAGE_ID"
task.wait(0.8)
until T == false
You could repeat the setting of the Image property as many times as you wish. Compared to setting the visibility for each instance, this method would cut down on the amount of operations you are doing by only setting one value per increment.
If I read your question right, yes. If you remove the ‘repeat until’ loop it would still work as intended, only it would not loop - it will run once as any Lua script.
Ok, yep you did read that right thanks again btw for going in depth on the looping and recorrecting me using the loop wrong its much appreciated some people get mad when others say that they used it wrong I’m not one of those people I love when people spot out my mistakes it makes me become a better scripter.