How do I only get 1 name instead of all of them

  1. I want to get 1 cube name which number that is inside the name matches with your level

  2. I’m getting all of the names but I want only one. the name should have number in it that matches with your level number.

  3. Not much, I don’t know what to search for or like how to word it. cause I don’t get what I want probably because how I have worded it.

current script:

		local Cubes = game:GetService("ReplicatedStorage"):WaitForChild("Cubes"):GetChildren()
		for i, cube in pairs(Cubes) do
			if cube:IsA("Part") then
				if cube.Name ~= "Main"..level.Value then
					local newcube = cube:Clone()
					print(newcube.Name)
					newcube.Name = "Main"
					newcube.Parent = Part.Parent
				end
			end
		end
		Part.Parent:Destroy()
	end
2 Likes

~= means does not equal, so youre getting all the cubes that dont match the level

heres how you can find an child instance with a given name

local Cubes = game:GetService("ReplicatedStorage"):WaitForChild("Cubes")
local cubeName = "Main" .. level.Value

local foundCube = Cubes:FindFirstChild(cubeName) -- search for the name under Cubes instance

if foundCube then -- check if it exists

end
1 Like

okay, I will try that. and I thought ~= means that it has some similarities but doesn’t have to be exactly the same. I dont know where It was like that or why did I think of this way. but ty

1 Like

you may have gotten it from similarity and congruence, where they also use ~= symbols in math

2 Likes