Why is it upgrading by itself


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

plssssssssssssssssssssssssssss answer

1 Like

Please use the code feature to post code, the screenshots are annoying to view. Type code/text between two `` for simple code like this and for long lines like yours between 6 ``````.

simple code, one line: ` code
more complex code between these: ``` multiline code
both followed by either another of that character or another three

1 Like
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local upgraderemote =    game.ReplicatedStorage:WaitForChild("Upgrade")


local upgrades = {
	{ Name = "DoubleCoins", Cost = 100, Multiplier = 2 },
	{ Name = "TripleCoins", Cost = 150, Multiplier = 3 },
	{ Name = "QuadCoins", Cost = 200, Multiplier = 4 },
}

local function findNextUpgrade(currentUpgrade)
	for _, upgrade in upgrades do
		print("Checking upgrade:", upgrade.Name, "with Multiplier:", upgrade.Multiplier)
		if upgrade.Multiplier == currentUpgrade + 1 then
			return upgrade
	end
		if upgrade.Multiplier ~= currentUpgrade then
			print("NOPE")
		end
		print(currentUpgrade)
		print(upgrade.Multiplier)
end
		return nil
end

local function handleUpgrade(player)
	local coins = player.leaderstats["🌈Lucky Blocks"].Value
	local level = player.leaderstats.Level.Value
	local upgrade = findNextUpgrade(level)

	if upgrade and coins.Value >= upgrade.Cost then
		coins = coins - upgrade.Cost
				player.leaderstats["🌈Lucky Blocks"].Value *= level.Value
	else
		print("NO WORK")
			end
	print(coins)
	print(upgrade)
		upgraderemote:FireClient(player)
	end

upgraderemote.OnServerEvent:Connect(handleUpgrade)``````

```local player = game.Players.LocalPlayer
local upgradeButton = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local upgradeRemote = ReplicatedStorage:WaitForChild("Upgrade")


upgradeButton.MouseButton1Click:Connect(function()
	upgradeRemote:FireServer(print("Fired"))
end)

upgradeButton.MouseEnter:Connect(function()
	upgradeButton.Size = UDim2.fromOffset(535, 115)
end)

upgradeButton.MouseLeave:Connect(function()
	upgradeButton.Size = UDim2.fromOffset(505, 95)
end)```
1 Like

Way better, thanks! Except you also have the `-symbols in the code which is not needed (you put them by accident probably).

First thing I see is you have if upgrade.Multiplier == currentUpgrade + 1 and in the screenshots I see that the submitted currentUpgrade is 0, but you do not have a multiplier set in upgrades when it is 1 (0+1 = 1), so it won’t find any upgrade.

Then you have player.leaderstats.Level.Value but before that use player.leaderstats["🌈Lucky Blocks"].Value. Did you maybe mean player.leaderstats["🌈Lucky Blocks"].Level.Value? Or is that as you meant? Also I would never use such icons in variable names, you may have devices you program on or let others program for you where they can’t see that icon and the whole project may get damaged because of that.

1 Like

the - symbols means subtract
the multiplier is gonna be because i dont have any upgrades, the upgrades are meant to multiply how much i earn so thats why the first upgrade is 2
the player.leaderstats.Level.Value is meant to show the upgrade level the player is so that i can then multiply the level the player is * coins earned so if theyre level 3 they earn 3x coins

1 Like