Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can i solve this math problem in scripting inside my game, it s weird ?

Asked by 3 years ago

So, it`s a dumb question, but how can i make ( if the player has 10 views, then he gets 1 money per second), and add the multiplier for example if the player has 20 views then he will get 2 money and so on, idk how to do the math, i already have the loop with wait(1) second and all, but idk how to make the math.

Folder.AddMoney.OnServerEvent:connect(function(plr)
    if plr.leaderstats.Views.Value >= 10 then
        plr.leaderstats.Money.Value = plr.leaderstats.Money.Value + ???
    end
end)

2 answers

Log in to vote
0
Answered by 3 years ago

Auto-Solved.

Ad
Log in to vote
0
Answered by 3 years ago

Here is a solution for anyone checking it out later on, or OP if they want to use this solution

Folder.AddMoney.OnServerEvent:connect(function(plr)
    local increase = math.Floor(plr.leaderstats.Views.Value/10)
    plr.leaderstats.Money.Value = plr.leaderstats.Money.Value  + increase   
end

math.Floor basically rounds down the number. Because of this, we get the views (e.g. 25), divide by 10 (10 views = $1/s). This will give us 2.5. OP wants it as the integer, so we use math.Floor, which makes it equal 2!

Answer this question