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

One card per player GUI?

I want it so that when the GUI is clicked, if the player does not have a card yet, then a card will be given to the player, here's my code:

script.Parent.MouseButton1Down:Connect(function()
	local cards = {100, 101, 102}
	if Player.Backpack:FindFirstChild(#cards) == nil then
		local Keycards = ReplicatedStorage.cards:GetChildren()
		local GetKeycard = Keycards[math.random(1, #Keycards)]
		game.ReplicatedStorage.KeyGiver:FireServer(GetKeycard)
end
end)

The problem is that when I click the GUI I get a card. When I click again I get another card, and so on. But I only want one card per player.

Help please?

1 answer

The problem is you're searching the player backpack for the length of your array. Basically put, you're searching the backpack for "3" because there's 3 elements in your array. Instead of :FindFirstChild(#cards) run the name of the card entity. If you need more help, provide a picture of your explorer with all relevant bits.

2 comments

0

I basically only have three card which is listed in the table (100, 101, 102). How would I run the name of the cards, from the table?

0

Change the numbers to strings, so the name of the cards, then run a for loop checking to see if that card exists in the players inventory for each card.

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