WHy cant i get when a child is added

local Location = script.Parent.Main.Chat.Chat


local function ClearChat()
	for _, V in pairs(Location:GetChildren()) do
		if V:IsA("TextLabel") then
			V:Destroy()
		end
	end
end


local count = 0

script.Parent.Main.Keyboard.ChildAdded:Connect(function()
	print(count)
	for _,v in pairs(Location:GetChildren()) do
		if v:IsA("TextLabel") then
			count = count + 1
		end
	end
	if count < 12 then
		ClearChat()
	end
end)

Im trying to check how many children are in a instance, but the value wont go up when on is added

it seems that the “location” variable is set to script.Parent.Main.Chat.Chat and the childadded event is set to script.Parent.Main.Keyboard. maybe that could be the issue?

also make sure to set the count back to 0 before the for i, v loop else the count number will keep going up.

now every time i add a child it clears the chat

Did you mean to have it as count < 12, or did you intend for it to be count > 12?

Forgot to respond i fixed the ssue turns out i was doing sum wrong but i forgot what it was, sorry

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