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?
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.