If one instance matches another, do this

Hi all,

I have a folder in the player which contains which ‘Rides’ they own and I also have a GUI that contains frames that would correspond to each ride. I need it to check that the corresponding value to each GUI exists in the Rides folder, and if not it will show the ‘Locked’ button - but only for that one frame and not all of them. I would need it to check each one idividually.

In the simpliest way… If a boolValue inside of the rides folder exists with the same name as one of the GUI frames, remove the locked button, else show the locked button. Hopefully this makes sense.

Here is what I’ve tried so far

local player = game.Players.LocalPlayer

while true do
	wait()
	for _, frames in pairs(script.Parent:GetChildren()) do
		for _, rides in pairs(player.Rides:GetChildren()) do

			if frames.Name == rides.Name then
				frames.Inner.Locked.Visible = false

			elseif not frames.Name == rides.Name then
				frames.Inner.Locked.Visible = true
			end
		end
	end
end

Any help is greatly appreciated - thanks! :smiley:

1 Like

can you show the explorer?
and is that a local script?

Yeah its a local script inside the GUI. What do you need to see of the explorer?

I have just written this script which works, however only for the one ride. I would need it to do this process but loop through it until it has tried to match each frame in the GUI with each BoolValue in the ‘Rides’ folder

local player = game.Players.LocalPlayer
local Rides = player.Rides


while true do
	wait()
	if Rides:FindFirstChild("Extreme") then
		script.Parent.Extreme.Inner.Locked.Visible = false
		
	elseif not Rides:FindFirstChild("Extreme") then
		script.Parent.Extreme.Inner.Locked.Visible = true
			
			end
		end

Locked is a property who is in Gui2D elements, indexing a children with the same name is not the best, try changing name or instead use ["Locked"].

1 Like

Couldn’t see this property but changed it just in case - thanks! Unfortunately not sure this will make the script work though :slight_smile:

1 Like

You can just use the else condition instead of elseif since else will work if the condition will be false.
By the way also you can directly use while task.wait() do if you dont have to put task.wait() inside the loop.
wait() is deprecated so use task.wait() instead.

1 Like

Thanks again. I assume none of these changes will help it to work in the way I need it to, just optimisation changes I guess?

1 Like

Yeah, being on phone atm i can’t fix your script, but don’t forget those optimizations.
I will try fix it later if not resolved by you or anyone else once ill be available. Goodluck.

1 Like

Awesome - thank you! I’ve changed them all in my script, and I’ll keep trying things I can think of to see if it works, if not then hopefully you or someone else may be able to give a hand

1 Like

Something to point out is that while true do or while wait/task.wait() do are not good on performance. while loops tell the code to do something while the given statement is false, but true and task.wait() are always going to prove to be true, which causes something called polling. Essentially it’s like asking the engine “Are we there yet?” every 1/60th of a second, which while task.wait() seems to fix on the surface, still will soon cause lag.

A lesser laggy solution is to event driven functions, such as frame:GetPropertyChangedSignal("Name"):Connect(function()

Laggy? It depends what do you put inside the loop. You use a loop when you constantly want to check or do something every X seconds, you use GetPropertyChangedSignal for specific situation and you dont want to yield the thread.
Im not correcting you entirely, just giving advice.
while task.wait() wouldnt make anything lag at anytime if its correctly used, example for A-Chassis using ~10 while true do and RunService events and scripts are working without anything break or create lags.

Thanks for this. To be most efficient I’m going to switch it to only update when the GUI is opened each time, so its not constantly checking for updates - even if this won’t have much of a performance impact.