And at the end of the game when the coundown gets to 0 I want it to go back to the normal coins, making sure all the time it is in a loop to check if the player grabbed a coin, spent or if the value changed
What I have so far and that does not work is this:
In the minigameHandler
if i == 0 then -- If the game started
displayManager.updateStatus("GO!")
displayManager.updateCoinStatus(player.leaderstats.InGameCoins.Value .. " / " .. player.leaderstats.MaxCoins.Value, player)
On the moduleScript
function DisplayManager.updateCoinStatus(newStatus,Player)
Player.PlayerGui.Coins.Gradient.Coins.Text = newStatus
end
On a localScript inside the coinText
local textLabel = script.Parent
local function updateText()
if status.Value == "GO!" then
textLabel.Text =player.leaderstats.InGameCoins.Value .. " / " .. player.leaderstats.MaxCoins.Value
end
if status.Value == "Game ended!" then
textLabel.Text = player.leaderstats.Coins.Value
end
end
status.Changed:Connect(updateText)
updateText()
Maybe I’m wrong or maybe I’m right, but I don’t see a code that updates the gui depending on how many coins the player has collected. I do see the module script, but it would only run once. With the changed function, it would run everytime the value has changed, or infinitely. You should add a function that detects everytime the “InGameCoins” value changes. When that happens, we update the coin value.
Also, since you wanted the coin value to change when the game ends, you can call the function updateText() and disconnect the .Changed event.
You were right with the first part, I added this function to check all the time if the value changes and works
local function updateCoins()
textLabel.Text = InGameCoins.Value .. " / " .. player.leaderstats.MaxCoins.Value
end
InGameCoins.Changed:Connect(updateCoins)
Now could you explain to me how to do the part when the game ends? I don’t really know how to approach it
if status.Value == "Game ended!" then
InGameCoins.Changed:Disconnect()
textLabel.Text = player.leaderstats.Coins.Value
end
InGameCoins.Changed:Connect(updateCoins)