Upgrade system doesn't work

I’ve been trying to make an upgrade system for the past few weeks but it’s not working out very well. The main part that isn’t working is the text label. It’s supposed to multiply the amount of times a player has upgraded by 1.5. However it seems to be multiplying the players multiplier by 1.5. Also when I play sometimes the text label says “0” and other times it says “1.5” which is really weird. No errors are shown in the output.

Data store script

local ds = game:GetService("DataStoreService"):GetDataStore("Upgrade_saving__dfjooo9")
local upgrade_folder = game.ServerStorage.Upgrades 

game.Players.PlayerAdded:Connect(function(plr)
  local item_fold = Instance.new("Folder")
  item_fold.Name = "upgrades"
  item_fold.Parent = plr

  upgrade_folder:FindFirstChild("UpgradesNumber")
    local upgrade = Instance.new("NumberValue")
    upgrade.Name = "UpgradesNumber" 
    upgrade.Parent = item_fold
    local data
    local succ, er = pcall(function()
	data = ds:GetAsync("UpgradesNumber"..plr.UserId)
	print("recoverd data")
	end)
        if not data then print("no data") end
        data = data or 1
        upgrade.Value = data
------------------
  upgrade_folder:FindFirstChild("UpgradeAmount")
	local upgradeAmount = Instance.new("NumberValue")
	upgradeAmount.Name = "UpgradeAmount"
	upgradeAmount.Parent = item_fold
	local data2
	local succ, er = pcall(function()
	data2 = ds:GetAsync("UpgradeAmount"..plr.UserId)
	print("recovered data")
	end)
		if not data2 then print("no data") end
			data2 = data2 or 1
			upgradeAmount.Value = data2
			print(upgradeAmount.Value)
		
end)
-----------------
  

game.Players.PlayerRemoving:Connect(function(plr)
  local succ, msg = pcall(function()
      ds:SetAsync("UpgradesNumber" .. plr.UserId, plr.upgrades.UpgradesNumber.Value) 
	  ds:SetAsync("UpgradeAmount" .. plr.UserId, plr.upgradeAmount.UpgradeAmount.Value)
    end)

    if not succ then
    warn("Problem with saving data ".. msg)
  end
end)

Text label script

local plr = game.Players.LocalPlayer

local upgrades = plr:WaitForChild("upgrades").UpgradesNumber

local upgradeAmount = plr:WaitForChild("upgrades").UpgradeAmount

local increase = 1.5

local function updateText(newValue)

script.Parent.Text = newValue * increase

end

upgrades.Changed:Connect(updateText)

updateText(upgradeAmount.Value)

Upgrade processing script

local Event = game.ReplicatedStorage.RemoteEvent

Event.OnServerEvent:Connect(function(player)

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local upgrades = player:WaitForChild("upgrades"):FindFirstChild("UpgradesNumber")

local upgradeAmount = player:WaitForChild("upgrades").UpgradeAmount

local increase = 1.5

local price = upgradeAmount.Value*increase

print(player.leaderstats.Elixir.Value)

if player.leaderstats.Elixir.Value >= price then

player.leaderstats.Elixir.Value = player.leaderstats.Elixir.Value - price

upgrades.Value = upgrades.Value + 0.01 ---The part where I add to the IntValue

upgradeAmount.Value = upgradeAmount.Value + 1

return true

else

return false

end

end)

Let’s check out the text label script.
Sometimes, when things aren’t working correctly, I do print() to make sure that it is receiving things correctly.
Have you tried printing what the server sends it?

1 Like

Yes I have

   local plr = game.Players.LocalPlayer
local upgrades = plr:WaitForChild("upgrades").UpgradesNumber
local upgradeAmount = plr:WaitForChild("upgrades").UpgradeAmount
print(upgradeAmount.Value) --------This prints 1
local increase = 1.5

local function updateText(newValue)
    script.Parent.Text = newValue * increase
    local price = newValue * increase
print(price) -----prints 0 and sometimes 1.5
end 

upgrades.Changed:Connect(updateText)
updateText(upgradeAmount.Value)

Sometimes in the text label script upgradeAmount.Value is “0” while other times it’s “1”
However in the data store script where it says print(upgradeAmount.Value) always prints “1”

Then, in that case, it’s an issue with the text label script.
If the data store script print 1, then something in the text label script is not doing well.

Let’s look here.
It seems your printing the upgrade amount, instead of upgrades.
Let’s look at this line.

What would happen if their upgrades were at 0?
or, the new value was at 0, or never changing?

Every player starts with upgrades.Value as 1. upgrades is the player’s multiplier
newValue is upgradeAmount.Value which is set to 1 and increases by 1 every time the player purchases an upgrade. However, sometimes newValue is 0 for some reason due to the fact that upgradeAmount.Value is 0

Then that means it’s never being changed.

It has to be an issue with your upgrade processing script.

Oh, so you mean the text will always say 0 in the beginning since upgrades doesn’t change until the player buys an upgrade?

1 Like

Correct.

aodasoddaasfaaghjghjhgghhggh

Sorry, I’m confused by what you mean. Isn’t the issue in the text label script?

1 Like

Not anymore.
You defined it.

“However, sometimes newValue is 0 for some reason due to the fact that upgradeAmount.Value is 0”
So, the script that is setting it(upgrade processing script) is the one in question since newvalue/upgradeamount is 0.

1 Like

Your script probably has a few errors.

1 Like

But it’s at 0 even before that script runs

Thanks for pointing that out, I had no clue what was causing it to not work.

1 Like