How to pick 3 out of 1

Hi, so basicly what i mean is lets say you have 4 cards right and then 1 is chosen as the “bad” card, And now the other 3 cards are gifts i already have a system that picks a random card makes it bad then stores it but i just need the last part where the rest of the cards are chosen as random gifts

heres my script:

local CollectSrvice = game:GetService("CollectionService")
local Storage = game:GetService("ServerStorage")

local Parent = script.Parent

local EvilDuckie = Storage.CardList.EvilDuckie

local Cards = {
	[1] = Parent.Card1,
	[2] = Parent.Card2,
	[3] = Parent.Card3,
	[4] = Parent.Card4
}

local ChosenEvilDuckie = {}


local Chosen = math.random(1, #Cards)

table.insert(ChosenEvilDuckie, Chosen)

Cards[Chosen].Card.Value = EvilDuckie.Name

print(Cards[Chosen].Card.Value)

print(ChosenEvilDuckie[1])
1 Like

Here, I think it will work:

local CollectionService = game:GetService("CollectionService")
local ServerStorage = game:GetService("ServerStorage")
local DataStoreService = game:GetService("DataStoreService")
local BadCardStore = DataStoreService:GetDataStore("BadCard")

local Parent = script.Parent
local Cards = {
    [1] = Parent.Card1,
    [2] = Parent.Card2,
    [3] = Parent.Card3,
    [4] = Parent.Card4
}
local Gifts = {}
local ChosenEvilDuckie = {}

local function pickRandomGifts()
    local giftCount = 3 -- Number of gift cards to generate
    local pickedGifts = {}

    while #pickedGifts < giftCount do
        local randomCard = math.random(1, #Cards)
        if not table.find(pickedGifts, randomCard) then
            table.insert(pickedGifts, randomCard)
        end
    end

    return pickedGifts
end

local function generateGifts(chosenEvil)
    local giftCards = pickRandomGifts()
    for _, gift in ipairs(giftCards) do
        if gift ~= chosenEvil then
            table.insert(Gifts, gift)
        end
    end

    return Gifts
end

local function handleGiftGeneration(player)
    local chosenEvil = ChosenEvilDuckie[1]
    local gifts = generateGifts(chosenEvil)

    -- Save bad card name to DataStore
    local evilCard = Cards[chosenEvil].Card.Value
    BadCardStore:SetAsync("BadCardName", evilCard)

    -- Assign gift cards to other players (excluding the chosen evil)
    for i, gift in ipairs(gifts) do
        local giftPlayer = player
        if gift ~= chosenEvil then
            giftPlayer = Players:GetPlayers()[gift]
        end

        local giftCard = Cards[gift].Card.Value
        giftPlayer.Card.Value = giftCard
    end
end

Players.PlayerAdded:Connect(function(player)
    handleGiftGeneration(player)
end)
1 Like

Thank you so much i changed it a bit but it still works!

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.