How can I make a good cash reward system

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to create a simple algorithm for a player to gain cash in a specific way

  2. What is the issue? Include screenshots / videos if possible!
    I haven’t really ran into any issues just having trouble creating a math equation for what I’m looking for

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve looked on here but so far haven’t found anything like what I’m looking for, I’ve tried having a separate value and having a script to loop a random number inside that value every second and multiply the cash by that random number but it didn’t really achieve what I was going for

So basically what I’m trying to achieve is a system that grants a random value, that gradually increases as another value goes up.

For example: I have a cash, and a follower value, when someone posts a video, their follower value increases, but I want the cash to increase in a random amount according to their follower value.
so if someone has 50 followers and is making 1-5 cash every video, I don’t want them to have 5000 followers and still be making the 1-5 cash every video.

do something like:

local cashAwarded
if followers < 50 then
local num = math.random(2)
if num == 1 then
cashAwarded = 50
else
cashAwarded = 25
elseif followers > 50 then
local num2 = math.random(2)
if num2 == 1 then
cashAwarded = 500
else
cashAwarded = 250
end
end
end

I like this idea, but Is there a way I could possibly make the number a little more random? Like right now it would be a 50/50 chance. I want it to have multiple possible values

you could do:

math.random(whatever_amount_here)

then set up more elseif statements

You could use

math.random(amount,amount + 10)

So you have always the same amount of randomness but it depends on your amount

1 Like

maybe this?

local give = 0
local chance = 50
local range1, range2 = (followers%5+1)*(followers^0.5), (followers%10+6)*(followers^0.5)
if math.random(1, 100) < chance then
	cash = math.random(range1, range2)
end

Edit: I can explain this if you want

1 Like
  1. if you have 0 followers, they would still get money.
  2. There would always be 11 possible amount they could get no matter how many followers they have, which is fine but not that good. Example:
    with 10 followers, you could get 10 - 20 cash.
    with 60 followers, you could get 60 - 70 cash

but that is the most basic, easiest, and fastest to do

2 Likes

Ok thank you, to change the amount of cash given, which numbers would I have to mess around with?

you mean this?

character limit is bad

Yea, do I change the range numbers? This has been working but the amount of cash given I’d like to reduce a little.

ok I will modify it so you can edit the amount. wait

try this

local cash = 0
local chance = 50
if math.random(1, 100) < chance then
    cash = math.random((followers%5+1)*(followers^0.4)*multiplier, (followers%10+6)*(followers^0.4)*multiplier)
end

Ok that’s a little better however sometimes it gives 0 cash

Edit: I fixed it, thank you so much for this.

Oops, now I am getting an error whenever the follower count reaches higher numbers. does this script update when the follower value changes?

ScriptError

Heres the script

local ls = player:WaitForChild("leaderstats")
local Followers = ls.Followers
local Cash = ls.Cash
local chance = 50
	if player.leaderstats.Followers.Value == 0 then
	player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 10
	player.leaderstats.Followers.Value = player.leaderstats.Followers.Value + 25
else
	if math.random(1,100) < chance then
		player.leaderstats.Cash.Value =  player.leaderstats.Cash.Value + math.random((Followers.Value%5+1)*(Followers.Value^0.3), (Followers.Value%8+6)*(Followers.Value^0.15))
	else
		player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + math.random(Followers.Value%3+1)*(Followers.Value^0.3)
	end
player.leaderstats.Followers.Value = player.leaderstats.Followers.Value + 1000

oh this is because the random cash you give is too much, it is turning into nil. Wait I am just modifying it

here I got it, the cash give value will max somewhere at 10^303. You can still edit the range and range2

Btw this is not good when there are multiple very very pro or high level players in one server, because there will be too many while do loops.

local ls = player:WaitForChild("leaderstats")
local Followers = ls.Followers
local Cash = ls.Cash
local chance = 50
	if player.leaderstats.Followers.Value == 0 then
	player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 10
	player.leaderstats.Followers.Value = player.leaderstats.Followers.Value + 25
else
	if math.random(1,100) < chance then
		local m = 0
		local range,dec = (Followers%5+1)*(Followers^0.3), 0
		local range2,dec2 = (Followers%8+6)*(Followers^0.15), 0
		if range > 1000 and range2 > 1000 then
			while range > 100 do
				range /= 10
				dec += 1
				m += 1
				if m >= 299 then break end
			end
			m = 0
			while range2 > 100 do
				range2 /= 10
				dec2 += 1
				m += 1
				if m >= 299 then break end
			end

		elseif range < 10 and range2 < 10 then
			while range < 1000 do
				range *= 10
				dec -= 1
				m += 1
				if m > 30 then break end
			end
			m = 0
			while range2 < 1000 do
				range2 *= 10
				dec2 -= 1
				m += 1
				if m > 30 then break end
			end
		end
		Cash += math.floor((Random.new():NextNumber(math.min(range,range2), math.max(range,range2)))
			*(10^math.random(math.min(dec, dec2), math.max(dec, dec2))))
	else
		player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + math.random(Followers.Value%3+1)*(Followers.Value^0.3)
	end
player.leaderstats.Followers.Value = player.leaderstats.Followers.Value + 1000