How do I reference or modify an instance based on a string?

In this function, it seems like you’re indexing/assuming that the TargetString you’re trying to search for is already there, but you have to implement some sort of sanity check first before doing so

What we use is a nifty function called FindFirstChild(), and what this does is that it searches for the name that you’re trying to look for inside the current children, and this can return back the Instance found, or nil

So adding on what we know here:

function leftClick()
	growtween:Play()
	wait(0.3)
	explosiontween:Play()
	wait(0.4)
	coverscreentween:Play()
	wait(2)
	local currentitem = itemnames[math.random(#itemnames)]
	--local TargetString = tostring(itemnames) We actually don't need this surprisingly, cause this is a table in itself is what we're getting
    local FrameCheck = gui.OwnedSkinGui:FindFirstChild(currentitem) -- If you're trying to find the specified name, use the "currentitem" variable

    if FrameCheck then -- Check if the UI Object you're searching for is there, if it is then we can change it!
        FrameCheck.BackgroundColor3 = Color3.fromRGB(134, 134, 134)
    else
        warn("Oops,", currentitem, "was unable to be found!")
    end

	gui.Example.Text = currentitem
	gui.ExplodeImage.Size = UDim2.new(0, 1, 0, 1)
	gui.SkinCrateImage.Size = UDim2.new(0, 1, 0, 1)
end

Your original code on line 27 was actually getting the string of a table, hence why it errored

2 Likes