#how do i make this earn "cash" every second

1 messages · Page 1 of 1 (latest)

cloud pebble
#

this is a module script

local stat = {}

stat.Defaults = {
    Rebirths = 0,
    Multiplier = 0,
    Cash = 0,
}

function stat.createLeaderstats(plr)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = plr

    for name, value in pairs(stat.Defaults) do
        local numberValue = Instance.new("NumberValue")
        numberValue.Name = name
        numberValue.Value = value
        numberValue.Parent = leaderstats
    end
end


return stat
#

also the leaderstats arent in order i was wondering how to keep it fixed (cash, multiplier, rebirth, etc)

magic token
#

task.spawn(function()
while true do
task.wait(1)
leaderstats.Cash.Value+=1
end
end)

#

place under the for loop in the module script

#

check with me if it doesnt work, been a while for me since I was on lua

fresh ridge
magic token
#

ah

#

good practice I guess

fresh ridge
#

leaderstats are ordered either by creation order, or some ordering settings, i cant remember what they are but you should be able to find it in the docs pretty easy now that you know such settings exist.

sinful tapir
#

dont use a modulescript if u dont know what it is

sinful tapir
fresh ridge
#

if the player leaves while the loop is running it will error. rather inconsequential but random errors should be avoided if you can help it, better to save those live error reports for actual errors instead of silly blunders like that.

#

ideally you'd set up this loop as either some event connection that you can disconnect, or task.cancel the thread, but op is stuck on simply starting the loop, so checking if player.parent is the easiest way to catch it

#

eh, it's the same

#

you could put a gate in there, but it resolves to going into the while loop condition all the same.

#

or you could just while true do task.wait() .. etc, it's all roughly the same thing

#

why would it only be once

#

while loop repeats until condition is false, and player.parent will always be true until the player leaves

#

ya those are usually called gates, and yeah you could do it like that if you want to.

sinful tapir
#

alright

fresh ridge
#

functionally identical.

fresh ridge
fresh ridge
fresh ridge
cloud pebble
#

oh bruh

cloud pebble
fresh ridge
#

you have not been stuck on this for a month

cloud pebble
fresh ridge
#

premature optimization most likely

cloud pebble
#

whats that

fresh ridge
#

it means you wasted time optimizing something that didn't need it at the time.

cloud pebble
#

o

fresh ridge
# cloud pebble where do i put this

anyway if you're having trouble with while loops i suggest you go back to basics and look up how they work again https://create.roblox.com/docs/tutorials/curriculums/core https://create.roblox.com/docs/tutorials/fundamentals/coding-1/coding-fundamentals
and at your level ai can probably give you a jumpstart on the basics, keep watching beginner tutorials etc, put them into practice. keep playing with it.
You're not expected to know exactly where to put stuff on your first attempt; you're expected to fiddle with it, play with it, break it apart and put it back together again, study and learn how it works.

#

but above all, do not expect to get it perfect, correct, optimal, or flawless on your first attempt. and that's totally okay, and totally normal.

cloud pebble
fresh ridge
#

you will never get good until you've already made the mistake of putting it in the wrong spot and learning why it was a bad spot, rine repeat many, many times.

fresh ridge
cloud pebble
#

btw the script makes 3 per cash

#

aand my game crashed

fresh ridge
cloud pebble
#

xd

#

im an experienced builder and i work with a couple people but im so

cloud pebble
sinful tapir
cloud pebble
#

most of the time its wrong

cloud pebble
fresh ridge
#

roblox has a few things to set leaderstats order; you should be able to look them up fairly easily

cloud pebble
#

ah i couldnt see it

novel wharf
#

what cash

#
while true do
  player.leaderstats.cash.Value += 1
  wait(1)
end```
cloud pebble
#

yes i got it working

novel wharf
#

looks fine

cloud pebble
#

now i gotta do data saving and gui and more other stuff like damn

#

but im slowly growing

#

im proud of myself

frozen ember
#

he was using number values instead of a module

sour reef
ember lichen
# fresh ridge 👍

Btw, I got question. For s2 you need to make a few good system (ofc clean, optimized etc) or one good system with more than 3 scripts would be enough ?

fossil ibex
sinful tapir
cloud pebble