#Tokens dont add?

1 messages · Page 1 of 1 (latest)

south dagger
#

So like i made this Script a few days ago and wanted to add some stuff, but well... I didnt make noted of what i was doing an now im kinda not knowing what i did lol
And yeah, the tokens wont add, but they should add so yhh its hard.

#
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEventsFolder = ReplicatedStorage:WaitForChild("RemoteEvents")


local InventorySetup = RemoteEventsFolder:WaitForChild("InventorySetup")
local DiceThrowEvent = RemoteEventsFolder:WaitForChild("DiceThrow")



local function D3(player, allDices)
    local Tokens = player:WaitForChild("leaderstats"):WaitForChild("Tokens")
    local randomFace = math.random(1, 3)
    print(randomFace)
    local thrownHand = player:WaitForChild("thrownHand")
    thrownHand.Value += randomFace
    Tokens.Value += randomFace
end

local function D4(player, allDices)
    local Tokens = player:WaitForChild("leaderstats"):WaitForChild("Tokens")
    local randomFace = math.random(1, 4)
    print(randomFace)
    local thrownHand = player:WaitForChild("thrownHand")
    thrownHand.Value += randomFace
    Tokens.Value += randomFace
end

local function CoinFlip(player)
    local Tokens = player:WaitForChild("leaderstats"):WaitForChild("Tokens")
    local thrownHand = player:WaitForChild("thrownHand")

    local randomFace = math.random(1, 2)
    print("CoinFlip:", randomFace)

    local gain = 0
    if randomFace == 1 then
        gain = 2 
    else
        gain = 0 
    end

    thrownHand.Value += randomFace
    Tokens.Value += randomFace + gain
end
#
local function DiceEvent(player, dice, dices)
    local baseName = string.match(dice.Name, "^(.-)_?%d*$") or dice.Name
    if baseName == "D3" then -- common
--        print("D3")
        D3(player, dices)
    elseif baseName == "D4" then -- common
--        print("D4")
        D4(player, dices)
    elseif baseName == "Coin Flip" then -- common / mby uncommon
--        print("Coin Flip")
        CoinFlip(player, dices)
    end
end



local function getFiveRandomDices(player)
    local DiceFolder = player:WaitForChild("DiceFolder")
    local dices = DiceFolder:GetChildren()
    local chosen = {}

    for i = 1, math.min(5, #dices) do
        local index = math.random(1, #dices)
        local dice = table.remove(dices, index)
        table.insert(chosen, dice)
    end

    local diceData = {}
    local DiceInvFolder = player:WaitForChild("DiceInvFolder")

    for _, diceObj in ipairs(chosen) do
        local faces = diceObj:FindFirstChild("Faces")
        local multiplier = diceObj:FindFirstChild("Multiplier")
        local rarity = diceObj:FindFirstChild("Rarity")
        local information = diceObj:FindFirstChild("Information")
        local id = diceObj:FindFirstChild("ID")

        if faces then
            local cleanName = diceObj.Name:match("([^_]+)")
            local multValue = multiplier and multiplier.Value or 1

            table.insert(diceData, {
                Name = cleanName,
                Faces = faces.Value,
                Multiplier = multValue,
                Rarity = rarity and rarity.Value or "Unknown",
                Information = information and information.Value or "",
                ID = id.Value
            })
        end

        local clonedDice = diceObj:Clone()
        clonedDice.Parent = DiceInvFolder


    end



    return diceData
end
#
DiceThrowEvent.OnServerEvent:Connect(function(player)
    local HandFolder = player:WaitForChild("HandFolder")
    local dices = HandFolder:GetChildren()

    local Tokens = player:WaitForChild("leaderstats"):WaitForChild("Tokens")
    local availableThrows = player:WaitForChild("availableThrows")
    local waveReq = player:WaitForChild("waveReq")
    local DicesInHand = player:WaitForChild("DicesInHand")

    local thrownHand = player:WaitForChild("thrownHand")


    for _, dice in ipairs(dices) do
        local baseName = string.match(dice.Name, "^(.-)_?%d*$") or dice.Name
        if baseName ~= "Coin Flip" then
            DiceEvent(player, dice, dices)
        end
    end


    for _, dice in ipairs(dices) do
        local baseName = string.match(dice.Name, "^(.-)_?%d*$") or dice.Name
        if baseName == "Coin Flip" then
            DiceEvent(player, dice, dices)
        end
    end



    for _, dice in ipairs(dices) do
        dice:Destroy()
    end


    DicesInHand.Value = 0
    thrownHand.Value = 0
    availableThrows.Value -= 1


    local fiveDiceData = getFiveRandomDices(player)
--    print(fiveDiceData)

    InventorySetup:FireClient(player, nil, fiveDiceData)



    if availableThrows.Value == 0 then
        if Tokens.Value >= waveReq.Value then
            print("You did it!!")

            DiceThrowEvent:FireClient(player)
        else
            warn("You Lost")
        end
    end

end)
misty knot
south dagger
#

why i dont get the Tokens added, only when i use Coin Flips its working sometimes, idk

misty knot
south dagger
#

thats one Script, ServerScript

south dagger
misty knot
south dagger
#

yes the print(randomFace) is not printing

#

only the print(randomFace) for the CoinFlip is working

misty knot
south dagger
#

Nvm i found it

#

so first i had them like D3_1 or D3_2 and more like that, so they have different names. But cloning got different, so i gave them ID's

misty knot
south dagger
#

but i still had this:


local baseName = string.match(dice.Name, "^(.-)_?%d*$")