How do I get a child if the name is a number?

I have a group in workspace and I’m trying to get a child of that model but the name is a number and keeps returning nil I index it. Any help thanks

local OpenShop = game.ReplicatedStorage:WaitForChild("OpenShop")

local Gui = script.Parent:WaitForChild("ScreenGui")
local Frame = Gui.Frame
local Background = workspace:WaitForChild("BackgroundGroup", 5)

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()

local Number = 1

OpenShop.OnClientEvent:Connect(function(Open)
	if Open then
		wait(0.25)
		
		Frame.Visible = true
		print(Background:FindFirstChild(tostring(Number))) -- nil
	end
end)
3 Likes

Maby you have a space behind the nummber?

All of the childs doesn’t have a space its named just 1, 2, 3, 4, etc and the variable is just 1.

Use tostring(number) to turn numbers into strings.

1 Like

Is this correct?

Any other solutions?

1 Like

you can use [] as in

Workspace["1"]

This would search for a part named 1 that is in the workspace, you can do that at any point in the hierarchy.

workspace.Model["1"]

wouldn’t WaitForChild or FindFirstChild with speech marks work? Like for example:

Background:WaitForChild("1")
-- or
Background:FindFirstChild("1")

Im searching for a child named 1 in a group not workspace

That works at any point in the hierarchy

workspace:WaitForChild("BackgroundGroup")["5"]

this searches for an instance named 5 within BackgroundGroup

image

Error:
image

Code:

local OpenShop = game.ReplicatedStorage:WaitForChild("OpenShop")

local Gui = script.Parent:WaitForChild("ScreenGui")
local Frame = Gui.Frame

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()

local Number = 1

OpenShop.OnClientEvent:Connect(function(Open)
	if Open then
		wait(0.25)
		Frame.Visible = true
		print(workspace:WaitForChild("BackgroundGroup")["5"])
	end
end)

I would manually check if Background:FindFirstChild(tostring(Number)) is not nil in Explorer

So I would use ~= operator to check if it is not nil?

can i see the object in the workspace hierarchy?

image

1 Like

there is no object named 5???

So I would just change the number 5 to 1 Since 1 is a child of the group?

image

workspace:WaitForChild("BackgroundGroup"):WaitForChild("1")

im running out of ideas

image

Code:

print(workspace:WaitForChild("BackgroundGroup"):WaitForChild("1"))