How would i add a number to a table?

  1. What do you want to achieve? I want to see if the children of a table is greater or = a number value

  2. What is the issue? Whenever i check if the children or equal to the number value , it doesn’t work

  3. What solutions have you tried so far? I looked at the devforum but i couldnt find any result, but i tried to search youtube, nothing works there.

--server

game.ReplicatedStorage.EggHatchingRemotes.Equippet.OnServerInvoke = function(player, petName)
	local nopetsequipped = #workspace.Player_Pets:FindFirstChild(player.Name):GetChildren()
	local ancientpet = {}
	local pet = game.ReplicatedStorage.Pets:FindFirstChild(petName,true)
	
	if pet.Isanicient.Value == true then
		table.insert(ancientpet, petName)
		local ancientchildren = ancientpet:Getchildren()

		if (ancientchildren + 1) <= player.Values.Maxancientequipped.Value then
			local clonedpets = game.ReplicatedStorage:FindFirstChild(petName , true):Clone()

			clonedpets.Parent= workspace.Player_Pets:FindFirstChild(player.Name)
			if player.anmultistrength.Value == "1" then
				player.anmultistrength.Value = player.anmultistrength.Value + (clonedpets.AncientMulti.Value - 1)
			elseif player.anmultistrength.Value > "1"then
				player.anmultistrength.Value = player.anmultistrength.Value + clonedpets.AncientMulti.Value
			end
			return "Equipped"
		elseif (ancientchildren + 1) > player.Values.Maxancientequipped.Value then
			return "Cant equip"
		


		end
	elseif  pet.Isanicient.Value == false then
		if  (nopetsequipped + 1) <= player.Values.Maxequipped.Value  then
			local clonedpets = game.ReplicatedStorage:FindFirstChild(petName , true):Clone()

			clonedpets.Parent= workspace.Player_Pets:FindFirstChild(player.Name)
			if player.multistrength.Value == "1" then
				player.multistrength.Value = player.multistrength.Value + (clonedpets.multistrength.Value - 1)
			elseif player.multistrength.Value > "1"then
				player.multistrength.Value = player.multistrength.Value + clonedpets.multistrength.Value 
			end


			return "Equip"

		elseif (nopetsequipped + 1) >= player.Values.Maxequipped.Value then
			return "Cant equip"


	end
	

end
--client

local function equippet()
	if selecte ~= nil then
		if selecte:FindFirstChild("Equipped").Value == false   then
			local result = rep.EggHatchingRemotes.Equippet:InvokeServer(selecte.Name)

			if result == "Equip" then
				equipbtn.TextLabel.Text = "Unequip"
				selecte.checku.Visible = true
				selecte:FindFirstChild("Equipped").Value = true

			elseif result == "Unequip"then
				equipbtn.TextLabel.Text = "Equip"
				selecte:FindFirstChild("Equipped").Value = false
				selecte.checku.Visible = false
			end
		else
			local result = rep.EggHatchingRemotes.Unequippet:InvokeServer(selecte.Name)

				if result == true then
				equipbtn.TextLabel.Text = "Equip"
				selecte.checku.Visible = false
				selecte:FindFirstChild("Equipped").Value = false
			end
		end
	end
end

Please help me ASAP, thank you

1 Like

Have you tried using #table, the # counts how many items there are in that table.

If you want to add a number into a table, you’ll need to look at 2 cases:

1.If the table is an array, you could use table.insert, and add that number.
2.If the table is dictionary, you’d need to assign that number with a keyvalue.
table:GetChildren() would work with objects that actually are objects, for example: bricks,models, clothes,etc. All of those, you could see them in your game explorer.

As long as I see, ancientpet contains strings that resemble pets, so you dont need GetChildren().
Simply change it into:
local ancientchildren = #ancientpet

1 Like