"If" does not hold for correct values player.folder:getChildren() ~= {} but he is {}

Hello, I had a problem that some item is created only in a certain folder at a certain time, and to prevent errors, I installed a check whether the table is empty, but even with an empty table, the function is executed, how to fix it?

game.Players.PlayerRemoving:Connect(function(player)
	print(player.OtherBoost:GetChildren()) -- I get "{}"
	
	if player.OtherBoost:GetChildren() ~= {} then --problem
		
	local tableOfDataBoost = {
		["HeavenBuff"] = os.time() + player.OtherBoost.HeavenBuff.Value
	}

	local success, errormessage = pcall(function()
		print(tableOfDataBoost)
			datastore:SetAsync(player.UserId, tableOfDataBoost)
	   
		end)
	end -- end "if"
end)

Wait so I am confused on your issue? Could you try explain it again.

player.OtherBoost:GetChildren() = {}

I checking player.OtherBoost:GetChildren() ~= {}

when the player exits the function checks this is the table empty.

But even when the table is empty (ie {}) the function is still executed

if (#player.OtherBoost:GetChildren() > 0) then
    -- // Code.
end

Here’s a better solution.

1 Like

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