Help, gui not updated when upgrading

in this video you can see that the gui is not updated when upgrading

Local script:

local Upgrades = {
	["Damage"] = {
		Price = 30,
		Amount = 100,
		Multiplier = 1,
	},
	["Coins"] = {
		Price = 100,
		Amount = 50,
		Multiplier = 1,
	},
	["Speed"] = {
		Price = 5,
		Amount = 15,
		Multiplier = 1,
	},
	["Lucky"] = {
		Price = 1000,
		Amount = 5,
		Multiplier = 1,
	},
}

local layoutOrder = 0

for UpgradeName, Upgrade in pairs(Upgrades) do
	local ClonedUpgradeTemplate = UpgradeTemplate:Clone()
	ClonedUpgradeTemplate.Name = UpgradeName

	ClonedUpgradeTemplate.UpgradeName.Text = UpgradeName
	ClonedUpgradeTemplate.UpgradePrice.Text = "Price "..Upgrade.Price
	ClonedUpgradeTemplate.UpgradeAmount.Text = "Amount "..Upgrade.Amount
	ClonedUpgradeTemplate.UpgradeMultiplier.Text = "x"..Upgrade.Multiplier

	layoutOrder += 1
	ClonedUpgradeTemplate.LayoutOrder = layoutOrder
	ClonedUpgradeTemplate.Visible = true
	ClonedUpgradeTemplate.Parent = UpgradesContainer

	ClonedUpgradeTemplate.UpgradeButton.Button.MouseButton1Click:Connect(function()
		if not UpgradeCooldown then
			if Upgrade.Amount >= 1 then
				UpgradeCooldown = true
				RemoteEvents.Upgrade:FireServer(Upgrade, UpgradeName)
				task.wait(0.3)
				UpgradeCooldown = false
			end
		end
	end)
end

Script:

RemoteEvents.Upgrade.OnServerEvent:Connect(function(player: Player,  upgrade: string, upgradeName: string)
	if upgrade and player.leaderstats.Coins.Value >= upgrade.Price and upgrade.Amount > 0 then
		player.leaderstats.Coins.Value -= upgrade.Price
		upgrade.Amount -= 1
		upgrade.Multiplier += 1

		RemoteEvents.Upgrade:FireClient(player, upgradeName, upgrade)
	end
end)

Your only changing it once, when you buy an upgrade, make sure the text updates

you dont have an upgrade.OnClientEvent

show me an example of how I can put this in there

on the side note: your method is vulnerable, anyone can set themselfs a negative price and infintie multiplier. You should store shop data on the server, or in a module script that both can easily access and ONLY send the upgrade name to the server and from the server send important data such as; the upgrade name, how much you have to purchase left and how much you have.
You can scale the price with a formula and DONT send that from the client to the server, do the calculation on both sides

RemoteEvents.Upgrade.OnClientEvent:Connect(function(upgradeName, upgrade)
UpgradesContainer[upgradeName].UpgradeAmount = upgrade.Amount
UpgradesContainer[upgradeName].UpgradeMultiplier = upgrade.Multiplier
end)
1 Like

I’ll try to convert this into a module now, thanks!

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