Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why is my FindFirstChild not finding the first child?

I am making a game where people can create levels to play. I was making a SurfaceGui to show the levels players are currently into, but when I try to get the owner value of the game with findfirstchild, I can't find it at all.

Here is the serverside code that creates that levels. I made sure to parent the "Player" objectvalue inside the map before parenting it to workspace.Games:

local newMap = map:Clone()
newMap.Name = player.Name.. "Game"
local v = Instance.new("IntValue")
v.Value = lvl
v.Name = "Level"
v.Parent = newMap
local p = Instance.new("ObjectValue")
p.Value = player
p.Name = "Player"
p.Parent = newMap
newMap:SetPrimaryPartCFrame(CFrame.new((freeSpace-1)*1000,0,0))
newMap.Parent = workspace.Games

Here is the code that finds the owner, which isn't actually finding it, printing only games[i].Name and then "Didn't find the owner!", which means the code doesnt breaks, no errors are being printed. It is fired on the events of workspace.Games.ChildAdded and ChildRemoved:

local games = workspace.Games:GetChildren()
	for i=1,#games do
		print(games[i].Name)
		local owner = games[i]:findFirstChild("Player")
		if owner then
			print("p")
			owner = owner.Value
			print("X")
			if owner and owner ~= player and owner.Parent == game.Players then
				print("p")
				local newBar = boardGui.Frame.UIListLayout.Bar:Clone()
				print("b")
				newBar.Parent = boardGui.Frame
				newBar.LayoutOrder = i
				newBar.PlayerName.Text = owner.Name
				newBar.Level.Text = "Level: " ..games[i].Level.Value
			end
		else print("Didn't find the owner!")
		end
	end

Also i tried print(games[i]:findFirstChild("Player")) on the command bar and it works, so I don't know why it doesnt on the localscript.

1 answer

So apparently roblox doesn't know how to handle objects that arent descendants of game, so I tried putting newMap on ReplicatedStorage before creating the player value and parenting it to workspace.Games and it worked now.

This discussion is preserved as it was. New answers, comments, and votes are closed.