#Tokens dont add?
1 messages · Page 1 of 1 (latest)
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)
Why not just slowly read through what you wrote, adding comments along the way?
You may not remember the bigger picture but you can figure it out, since you wrote it
i'll make notes next time, but do you see what i did wrong?
why i dont get the Tokens added, only when i use Coin Flips its working sometimes, idk
it's a lot to parse through on mobile.
Are these all server scripts? In what type of script do you add to the token .Value?
thats one Script, ServerScript
you can look at it later when your on Pc or on whatever
Okay, so add some prints to the flow of logic. What prints? Does anything not print? Are any of the inputs incorrect if you print them out?
yes the print(randomFace) is not printing
only the print(randomFace) for the CoinFlip is working
So that probably means the issue lies with the D3 & D4 functions. Add a print to where they should be called. Is it ever reaching that?
they dont get called, why? I have no clue. They should get called but they dont get
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
And this is why we debug. We won't always know the issue immediately, but we can narrow it down.
but i still had this:
local baseName = string.match(dice.Name, "^(.-)_?%d*$")