Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

One card per player GUI?

Asked by 6 years ago

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

Log in to vote
0
Answered by
Tomstah 401 Moderation Voter
6 years ago

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.

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? Florian27 76 — 6y
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. Tomstah 401 — 6y
Ad

Answer this question