I have multiple remote functions for my shop script. The first part returns a table that has the sword's name and the cost of the sword. The other OnServerInvoke checks if the player already owns the sword. On the client, it updates the text based off what the server returns. The final part of the serverscript will check if player wants to equip or unequip the sword, or purchase if they don't own it.

My problem is, the equip button they click is not changing their value correctly, it will change their equippedSword value to a different sword than they clicked on.

--server
getTools.OnServerInvoke = function(player)
	local swords = {}

	for swordIndex, sword in pairs(serverStorage:WaitForChild("Swords"):GetChildren()) do
		table.insert(swords, {sword.Name, sword:FindFirstChild("Cost").Value})
	end

	return swords
end

swordOwnership.OnServerInvoke = function(player, swordName)
	if serverStorage.PlayerData[player.Name].Inventory:FindFirstChild(swordName) then
		return true
	else
		return false
	end
end

buyButtonUpdate.OnServerInvoke = function(player, swordName)
	if serverStorage.PlayerData[player.Name].EquippedSword.Value == swordName then
		return "Unequip"
	else
		return false
	end
end

--client
for elementIndex, element in pairs(itemFrame:GetChildren()) do
	if element:IsA("ImageButton") then
		element.MouseButton1Click:Connect(function()
			local ownsSword = swordOwnership:InvokeServer(getTools[elementIndex][1])
			
			if ownsSword == true then
				local textUpdate = buyButtonUpdate:InvokeServer(getTools[elementIndex][1])
				
				if textUpdate == "Unequip" then
					buyLabel.Text = "UNEQUIP"
					killsCost.Text = "Owned"
					selectedItem.Value = getTools[elementIndex][1]
				else
					buyLabel.Text = "EQUIP"
					killsCost.Text = "Owned"
					selectedItem.Value = getTools[elementIndex][1]
				end
			else
				buyLabel.Text = "BUY"
				killsCost.Text = getTools[elementIndex][2] .. " Kills"
				selectedItem.Value = getTools[elementIndex][1]
			end
			
			itemName.Text = element.DisplayName.Value
			itemImage.Image = element.ImageId.Value
		end)
	end
end