Need help with upgrade save script

Hello, Im currently trying to make an upgrade saving system in my game.

  1. I have a folder in player, which have boolValues
  2. I buy an upgrade on the client, I use remote function to set boolvalue to true
  3. On server im trying to set value
  4. It returns nil
-- Server
UpgradeSaveRemote.OnServerInvoke = function(player, UpgradeValue, UpgradeName)

		Player.UpgradeStatus[UpgradeName].Value = UpgradeValue

	end


-- Client
local result = UgradeSaveRemote:InvokeServer(isUpgradeBoughtValue, Item.Name)if Freakiness.Value >= Product.Cost then
			
			-- Adding multiplier
			UpgradePurchased:FireServer(Product)
			
			Frame.TextButton.Text = 'Bought'
			Frame.TextButton.BackgroundColor3 = Color3.new(0.462745, 0.462745, 0)
			Frame.TextButton.Active = false
			
			isUpgradeBoughtValue = true

			local result = UgradeSaveRemote:InvokeServer(isUpgradeBoughtValue, Item.Name)
			
			print(result)
			
			
			
		end

List of upgrades:

image

1 Like

if youre talking about these lines its because the server doesnt return anything

This is how i create upgrades values:

local UpgradeStatus = Instance.new('Folder', Player)
UpgradeStatus.Name = 'UpgradeStatus'
	
local isUpgradeBought1 = Instance.new('BoolValue', UpgradeStatus)
isUpgradeBought1.Name = 'Freaky cat'

local DataToSave = DS:GetAsync(Player.UserId)
	
	if DataToSave then
		Freakiness.Value = DataToSave[1]
		
		isUpgradeBought1.Value = DataToSave[2]
else
		print('No data')
		
		local ValuesToSave = {
			Freakiness.Value,
			
			isUpgradeBought1.Value,

DS:GetAsync(Player.UserId, ValuesToSave)


1 Like

Can i ask why, because Im not good at creating remote functions

UpgradeSaveRemote.OnServerInvoke = function(player, UpgradeValue, UpgradeName)
		Player.UpgradeStatus[UpgradeName].Value = UpgradeValue
	end

because theres no return in the servers code

idk what youre trying to return but if you want the value that the server set it to then do this

UpgradeSaveRemote.OnServerInvoke = function(player, UpgradeValue, UpgradeName)
		Player.UpgradeStatus[UpgradeName].Value = UpgradeValue
		return UpgradeValue               
	end
1 Like

Great, now it returns the value, thank you.

Also, if value == 1, buy button needs to be turned inactive and change its color, but it doesnt work:

local result = UgradeSaveRemote:InvokeServer(isUpgradeBoughtValue, Item.Name)
			
			if result == true then
				Frame.TextButton.Active = false
				Frame.TextButton.BackgroundColor3 = Color3.new(0.462745, 0.462745, 0)
				Frame.TextButton.Active = false
			end

Do i need to create a new remote event to do this?

can you show what the Frame variable is

-- Upgrades display
for i, Item in pairs(UpgradesModule.Upgrades) do
	
	local Frame = TemplateUpgrade:Clone()
	
	local isUpgradeBoughtValue = Player.UpgradeStatus[Item.Name].Value
	local UpgradeSaveName = Player.UpgradeStatus[Item.Name]
	
	Frame.Parent = UpgradesFrame.UpgradesSection.ScrollingFrame
	
	Frame.Name = tostring(i)
	Frame.ImageLabel.Image = Item.Image
	Frame.UpgradeName.Text = Item.Name
	Frame.MultiplierAmount.Text = tostring(Item.Multiplier)..'x'
	Frame.CostAmount.Text = tostring(Item.Cost)..'👅'
	
	
	-- Upgrades purchasing
	Frame.TextButton.MouseButton1Click:Connect(function()
		
		local Product = nil

		for i, Item in pairs(UpgradesModule.Upgrades) do
			if Item.Name == Frame.UpgradeName.Text then
				Product = Item
			end
		end
		
		if Freakiness.Value >= Product.Cost and isUpgradeBoughtValue == false then
			
			-- Adding multiplier
			UpgradePurchased:FireServer(Product)
			
			Frame.TextButton.Text = 'Bought'
			Frame.TextButton.BackgroundColor3 = Color3.new(0.462745, 0.462745, 0)
			Frame.TextButton.Active = false
			
			isUpgradeBoughtValue = true

			local result = UgradeSaveRemote:InvokeServer(isUpgradeBoughtValue, Item.Name)
			
			if result == true then
				Frame.TextButton.Active = false
				Frame.TextButton.BackgroundColor3 = Color3.new(0.462745, 0.462745, 0)
				Frame.TextButton.Active = false
			end
			
			
			
		end
		
	end)
	
end

the code seems to be right, you might just not see it because youre changing the BackgroundColor to the same as it was already set here:

I tried to delete that, but this doesnt work.

Basically I need to change this button properties if value is true, so if player rejoin when he bought the upgrade, he cant buy it again

then you will need to save the value with datastores and when creating the upgrade buttons check if its already bought

-- Upgrades display
for i, Item in pairs(UpgradesModule.Upgrades) do
	
	local Frame = TemplateUpgrade:Clone()
	
	local isUpgradeBoughtValue = Player.UpgradeStatus[Item.Name].Value
	local UpgradeSaveName = Player.UpgradeStatus[Item.Name]
	
	Frame.Parent = UpgradesFrame.UpgradesSection.ScrollingFrame
	
	Frame.Name = tostring(i)
	Frame.ImageLabel.Image = Item.Image
	Frame.UpgradeName.Text = Item.Name
	Frame.MultiplierAmount.Text = tostring(Item.Multiplier)..'x'
	Frame.CostAmount.Text = tostring(Item.Cost)..'👅'
	

	if isUpgradeBoughtValue == true then 
		Frame.TextButton.Active = false
		Frame.TextButton.BackgroundColor3 = Color3.new(0.462745, 0.462745, 0)
		Frame.TextButton.Active = false
	end

	
	-- Upgrades purchasing
	Frame.TextButton.MouseButton1Click:Connect(function()
		
		local Product = nil

		for i, Item in pairs(UpgradesModule.Upgrades) do
			if Item.Name == Frame.UpgradeName.Text then
				Product = Item
			end
		end
		
		if Freakiness.Value >= Product.Cost and isUpgradeBoughtValue == false then
			
			-- Adding multiplier
			UpgradePurchased:FireServer(Product)
			
			Frame.TextButton.Text = 'Bought'
			Frame.TextButton.BackgroundColor3 = Color3.new(0.462745, 0.462745, 0)
			Frame.TextButton.Active = false
			
			isUpgradeBoughtValue = true

			local result = UgradeSaveRemote:InvokeServer(isUpgradeBoughtValue, Item.Name)
		end
		
	end)
	
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.