Hello! My name is Ethan and I have recently started to learn how to script, this is my problem:
So i’m doing this simulator type game test(mainly to test my scripting capability), and there are multipliers that multiply the points you get by the number of the multipliers number. I am trying to make the multiplier cost more than the last time you purchased it, with the cost increasing in reasonable increments.
So i realized that it would be too easy if the cost of the multiplier is constantly 10 cash, so i did this:
local price = 10
game.ReplicatedStorage.Multiplus.OnServerEvent:Connect(function(player) -- This remote event is for a gui.
if player.leaderstats.Cash.Value >= price then
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - price
player.leaderstats.Multiplier.Value = player.leaderstats.Multiplier.Value + 1
price = price * player.leaderstats.Multiplier.Value
else
print("You're poor lol")
game.ReplicatedStorage.NeedMoreMoney:FireClient(player)-- this makes a gui pop up telling you that you need more money
end
end)
As you can see I tried multiplying the price by the multipliers value but that means that the cost will start of as 10 and then it will continue to multiply that same number so:
10x2 = 20
20x3 = 60
60x4 = 240
240x5 = 1200 and so on until it becomes unreasonably high.
Then i changed it so that the price is 10x the multipliers value, but that became too easy, it was just going to be: 10; 20; 30; 40; 60; 70 and so on.
Would there be a way for me to make the price a specific number according the multiplier they have without using a bunch of if-statements?
Thank you for reading any help will be much appreciated.
I can’t quite understand what you need help with in your question. What do you need help or feedback on?
Sorry, my bad I edited it.
Its late at night for me and i’m tired
So basically you want to try and multiply the cost of the previous amount instead of a preset number? What exactly are you stuck on?
I’m stuck with the increments either being too small or too big.
So basically you want to find a reasonable amount to increase the next number by?
Would there be a way for me to make the price a specific number according the multiplier they have without using a bunch of if-statements?
Yes, I would want that. (30char)
You can use something like:
layer.leaderstats.Multiplier.Value = player.leaderstats.Multiplier.Value * 2
This will multiple the previous multiplier by itself without having to set a pre defined increment. You can change 2 to adjust how much you want to multiply it by.
I want to change the price of the multiplier not the multiplier itself.
Well I don’t know what is reasonable for your games progression and how easy it is to earn cash so I can’t explain the best way for a reasonable multiplier to add for the next price cost.
I understand thanks for all the help anyways!
If this question is more about arranging code, you could do the following:
--create a hardcoded dictionary with the multiplier value and the price
local multiplierPriceDictionary = {
[1] = 200
[2] = 500
[3] = 1000
}
game.ReplicatedStorage.Multiplus.OnServerEvent:Connect(function(player) -- This remote event is for a gui.
local multiplierValue = player.leaderstats.Multiplier.Value
if multiplierPriceDictionary[multiplierValue] then --first we check wether the multipliervalue exists in the dictionary
--if the multiplierValue == 2, the price would be 500
local price = multiplierPriceDictionary[multiplierValue]
if player.leaderstats.Cash.Value >= price then
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - price
player.leaderstats.Multiplier.Value = player.leaderstats.Multiplier.Value + 1
else
print("You're poor lol")
game.ReplicatedStorage.NeedMoreMoney:FireClient(player)-- this makes a gui pop up telling you that you need more money
end
end
end)