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

Getting an unowned card when player clicks the GUI?

Asked by 6 years ago

This is my code:

--//Service
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local Players = game:GetService('Players')

--//Variables
local Player = Players.LocalPlayer
local Keycards = ReplicatedStorage.Keycards:GetChildren()

--//MainScript
script.Parent.MouseButton1Down:Connect(function()
    if Player.Backpack:FindFirstChild('Keycard') == nil then
        if Player.Character:FindFirstChild('Keycard') == nil then

        local GetKeycard = Keycards[math.random(1, #Keycards)]
        GetKeycard.Parent = Player.Backpack
end
end
end)

The problem with this code is that when player 1 clicks the GUI, player 1 will get the card. But then if player 2 clicks the GUI, player 2 will also get the card from player 1.

I only want the person to be able to get a card if it is available (unowned by anyone).

Any help please?

Answer this question