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

Why won't this function detect when an item is in the players backpack?

local function checkInventory(player)
		for i, v in pairs(game.Players:GetPlayers()) do
			local backpack = v.Backpack
			local contents = backpack:GetChildren()
			if contents ~= ("XTREME_ENRGY") then
				v.Character.Humanoid.Health = 0
			end
		end
	end

The goal of this function is to check if a certain item is in a players backpack and if not, kill them, but even when I put the correct item in the players backpack it still kills them, why is this?

1 answer

On line 5, you're trying to see if the table you created with the :GetChildren() command is not equal to XTREME_ENRGY

to check if Backpack doesn't have something inside you can do this:

local backpack = --//path to backpack
local char = --//path to character instance

if backpack:FindFirstChild("XTREME_ENRGY") == false then
	char.Humanoid.Health = 0
end

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