Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Roblox: Function not looping or adding to the "money" value

I was programming a Roblox game, and I need a timer that loops, and it must add to the money IntValue. I play tested the code, but it did not loop or add to the money value. How would I solve this problem? There aren’t any errors occurring.
Here’s the code for the timer script. It is in a local script.

local minutes = 0
local seconds = 15

local player = game.Players.LocalPlayer
local leaderstats = player:FindFirstChild("leaderstats")
local money = leaderstats:FindFirstChild("Effect Coins")

while true do
    for i = 1, 15 do
        wait(1)
        if seconds == 0 then
            minutes = minutes - 1
            secconds = 59
        else
            seconds = seconds - 1
        end
        
        if seconds < 10 then
            script.Parent.Text = tostring(minutes)..":0"..tostring(seconds)
        else
            script.Parent.Text = tostring(minutes)..":"..tostring(seconds)
        end
    end
    
    money += 1
    minutes = 0
    seconds = 15
    
end

I tried changing the value of the time lengths, but it doesn’t seem to work.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

From the snippet you have provided, it seems like your code does not even run properly since there are errors like:

Typos in variable:

secconds = 59

Lua does not have operator +=. Instead use:

seconds = seconds + 1

There might be another problem. When you search for money.

leaderstats:FindFirstChild("Effect

It returns reference to object. When you want to change the object you have to access its property or method.

I have never programmed anything in roblox, but i have found in documentation reference to text label. It contains property named "ContentText", what means you can change money by doing this: money.ContentText = "money value"

Link to documentation

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading