Need help with this script That is not changing the icons when the code is being ran

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.

local NoWifi = script.Parent.NOWIFI
local LowWifi = script.Parent.LOWWIFI
local NearWifi = script.Parent.NEARWIFI
local FullWifi = script.Parent.FullWIFI
local OverMidWifi = script.Parent.OMIDWIFI
T = true
repeat
	FullWifi.Visible = false
	OverMidWifi.Visible = false
	NearWifi.Visible = false
	LowWifi.Visible = false
	NoWifi.Visible = true
	wait(.8)
	FullWifi.Visible = false
	OverMidWifi.Visible = false
	NearWifi.Visible = false
	LowWifi.Visible = true
	NoWifi.Visible = false
	wait(.8)
	FullWifi.Visible = false
	OverMidWifi.Visible = false
	NearWifi.Visible = true
	LowWifi.Visible = false
	NoWifi.Visible = false
	wait(.8)
	FullWifi.Visible = false
	OverMidWifi.Visible = true
	NearWifi.Visible = false
	LowWifi.Visible = false
	NoWifi.Visible = false
	wait(.8)
	FullWifi.Visible = true
	OverMidWifi.Visible = false
	NearWifi.Visible = false
	LowWifi.Visible = false
	NoWifi.Visible = false
until T == false

image
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)

1 Like

If there are any more info you guys need, I got you covered just let me know.

1 Like

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.

1 Like

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 :pray:

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.

Let me know if you need any more help!

1 Like

This actually helps a lot thank you so much. So, can this work for anything without a loop to?

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.

1 Like

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.

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