Issue with FindFirstChild

I’m running on 2 hours of sleep here, so if this issue seems braindead I apologize lol

I’m currently creating a system where the game will auto input a bounty on a bounty board i made every 500 or so seconds. Problem is, instead of finding the first child it just takes every child. Was this always the intended design?

How would I fix this?

Model Structure:


	if not bountygiven then
		local bountdelay = rng:NextInteger(200, 500)
		bountygiven = true
		local bountyinfo = {
			name = names[randomname],
			status = "TYPE: AI",
			desc = crimes[randomcrime],
		for i, v in pairs(workspace.SV_BountyBoard.Posters:GetChildren()) do
			if v:FindFirstChild("Used", true) then
				if v.Used.Value == false then
					v.Used.Value = true
					v.Transparency = 0
					v.SurfaceGui.Enabled = true
					v.SurfaceGui.Desc.Text = bountyinfo.desc
					v.SurfaceGui.NameText.Text =
					v.SurfaceGui.Status.Text = bountyinfo.status

What do you mean by “it just takes every child”?

Instead of just taking the first child it finds, it takes every child with the name given.

Maybe remove the second parameter from the FindFirstChild() call?

Okay, so reading between the lines…

Add a break to your loop after finding an unused bountyposter

1 Like

I did it with and without it, didn’t make a difference.

Yep lol, adding ‘break’ or ‘return’ fixes the issue. Yikes that was simple lol, thanks.

2 hours sleep… I’ve been there!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.