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)