Upgrade button help


image
I’m trying to make a system where theres multiple upgrades, a button where you can upgrade and it says your upg level in a text etc if you have upgraded 3 times it say “Level 3”, but it isn’t working, pls help me

1 Like

I don’t think you need that upgrade variable for this, all you really need is to check if your coins are greater or equal to the upgrade’s cost.

Also a few other things

You don’t pass in the name of the upgrade in the FireServer, so upgradeName will always be nil.

And you might need to refactor your upgrade code entirely as you’re assuming upgrade is a value in your upgrades table when in reality it’s just a true or false (boolean), you need to code some way to detect the next upgrade the player can get, perhaps by comparing the Multiplier, and t hen use that next upgrade to check the cost

sorry am new to scripting, i changed it to this


but still no work

Changing the upgrade variable to upgrades.Cost won’t fix it either

You need to find some way to get the next upgrade possible to buy, which I believe you could simply grab player.multipler, add 1 to it and go through all your upgrades via a loop to find one that has the same multiplier and use that for your upgrade variable

Example of looping through your upgrades explained here

1 Like


i’m dumb, how do i explain to the script that if the player owns an upgrade, the coins earned is “coins * multiplier”…

1 Like


i changed some stuff but still aint working

1 Like

You’re pretty close, the findNextUpgrade function looks to be how I said in my post

Next up you need to change how you use it, you’re close with using it on the upgrade variable, but you need to pass in where the multiplier for the player is stored, currentUpgrade is useless in this case.

Then you can get the cost, name and multipler from there

I assume the upgradeName parameter is the names within the upgrades variable. (Ex. “DoubleCoins”)

This is a little different from what you have, but I hope this might point you to the right direction.

if you try to use this code, remember to replace the [“Lucky Blocks”] with your name that includes the emoji.

local upgrades = {
	DoubleCoins = {Cost = 100, Multiplier = 2},
	TripleCoins = {Cost = 100, Multiplier = 3},
	QuadCoins = {Cost = 100, Multiplier = 4}
}

function handleUpgrade(player : Player, upgradeName : string)
	local upgrade = upgrades[upgradeName]
	local coins = player.leaderstats["Lucky Blocks"] -- Replace "Lucky Blocks" with your name that includes emoji"
	
	if upgrade and coins.Value >= upgrade.Cost then
        coins.Value = coins.Value - upgrade.Cost
		print("Level " .. upgrade.Multiplier)
	else
		print("Not enough coins to buy this upgrade or invalid upgrade name")
	end
end
1 Like


why error? is this good?

You don’t have a currentUpgrade variable, if you have a value on the player that stores their multiplier use that instead, otherwise make that value

I made one
image
but how do i tell the script that, the level.value * coins.value is how much the player is gonna earn

image
btw with the “currentUpgrade”, i’m calling the currentupgrade in the function

That’s not how it works, currentUpgrade in the function is a parameter name, it doesn’t mean anything until you pass in a correct value

local function test(bob)
    print(bob + 5)
end

test(bob) -- This will not work because there's no variable named bob
test(5) -- This will work

That’s why you need something to store the player’s current upgrade to then use

i changed to level instead, level stores the current upgrade aka level that the player is
image

but how do i tell the script that the player now earns coins * the level it is, so if the player is level 3 it earns 3 times more coins,


also getting the print that its not enough but i do have over 100 coins to buy

Whenever you reward coins to the player, multiply by the level

Also as for the coins problem, print out and coins and see what the server sees, you might be changing the coins on the client/locally, which the server can’t see

image
im already giving the coins at the top, should i change for bottom

image
the coins im printing are the same as what i have
image

image
printet upgrade and its nil thats my issue