Equipped system help!

I need to make the script go through the Equipped values in the folder and if the values are true then apply the picture to the name rocket
What is the best way to do this system?

local EquippedImage = player.PlayerGui:WaitForChild("MainRocketGUI").MainFrame.Frame.CurrentRocket

function UpdateEquippedRocket()
	local equippedRocketName = nil
	local RocketFolder = player:WaitForChild("RocketFolder")

	
	for _, rocketFolder in ipairs(RocketFolder:GetChildren()) do
		local equipped = rocketFolder:FindFirstChild("Equipped")
		local nameValue = rocketFolder:FindFirstChild("RocketName").Value
		if equipped and equipped:IsA("BoolValue") and equipped.Value and nameValue and nameValue:IsA("StringValue") then
			equippedRocketName = nameValue.Value
			break
		end
	end

	if equippedRocketName then
		for _, rocket in ipairs(RocketData.rockets) do
			if rocket.name == equippedRocketName then
				EquippedImage.Image = rocket.image
				print("Equipped rocket: " .. rocket.name)
				return
			end
		end
	else
		EquippedImage.Image = "rbxassetid://NONE" 
		print("No equipped rocket found")
	end
end

UpdateEquippedRocket()

local RocketFolder = player:WaitForChild("RocketFolder")
for _, rocketFolder in ipairs(RocketFolder:GetChildren()) do
	local equipped = rocketFolder:FindFirstChild("Equipped")
	if equipped and equipped:IsA("BoolValue") then
		equipped.Changed:Connect(UpdateEquippedRocket)
	end
end

RocketData is a module that is all about rockets.

image

what’s the problem with your script?

by the way I would use an ObjectValue for the equipped rocket

The problem is that the script should recognize the rocket and inside it equipped and then if equipped.Value == true then substitute the image of the rocket in EquippedImage

Well, for some reason it doesn’t recognize the rocket and says it doesn’t exist.
output:EquippedImage.Image = “rbxassetid://NONE”

that’s where the rocket’s image should come from:
image

I found the issue:

local nameValue = rocketFolder:FindFirstChild("RocketName").Value
if equipped and equipped:IsA("BoolValue") and equipped.Value and nameValue and nameValue:IsA("StringValue") then

nameValue is not a StringValue because you wrote .Value at the end, it’s a string

I found another solution it turns out just had to wait for the player and his folder to load for one millisecond, but thanks for that too, that was one of the reasons too :upside_down_face: