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

Not working when checking player backpack?

I am making an Obby and I am using keycards to get through a door, but I want there to be infinite keycards (so that do not run out), so I put very many keycards. But now one player can take all if they want :( I tried this script:

script.Parent.FindPlayers if player.Backpack == (’Keycard’) then script = false

script.Parent.FindPlayers if player.Backpack == (’Keycard’) -1 then script = true

What did I do wrong?

1 comment

0

Another idea (I'm not a very script changing person) is you could use GetChildren and limit it to one (not for multiple KEYCARDS)

2 answers

✓ Accepted answer

Hi! I'm new here so sorry if my answer looks weird, but I think I know why it's not working.

Okay, so first, I don't think "FindPlayers" exist. I think you're trying to use "GetPlayers", but I don't think it's necessary in something like this.

Second, I think you should use "for i,v in pairs" as it completely searches through their backpack.

Here's an example :

script.Parent.Touched:Connect(function(hit) --Script is in a part
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player then --Makes sure touched part is a player
		for i,v in pairs(player.Backpack:GetChildren()) do --Gets every item in backpack
			if v.Name == 'Keycard' then --Checks if any are named "Keycard"
				print(player.Name.." has keycard!")
			else
				print(player.Name.." doesn't have a keycard!")
			end
		end
	end
end)

If a player has anything named "Keycard" in their backpack, the game will print that the player has the keycard. If not, then it'll print saying the player doesn't have a keycard. You can put your own code in the prints so it can work the way you want it to.

Hope this helps! :D

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