Earlier today I was making a script that multiplies the player’s multiplier by 1.5. I realized that the cost would increase by hardly anything, so I added a new value to multiply by 1.5. This new value is based on the amount of times the player has purchased the multiplier instead of the multiplier’s value itself. Just some background info.
20:01:38.669 - Players.Play_MazeOfHeck.PlayerGui.ScreenGui2.Upgrade.Cost.Cost:11: attempt to index nil with 'Value'
local plr = game.Players.LocalPlayer
local upgrades = plr:WaitForChild("upgrades"):FindFirstChild("UpgradesNumber")
local upgradeAmount = plr:WaitForChild("upgrades"):FindFirstChild("UpgradeAmount")
local increase = 1.5
local function updateText(newValue)
script.Parent.Text = newValue * increase
end
upgrades.Changed:Connect(updateText)
updateText(upgradeAmount.Value)
ServerScript
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"
upgrade.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)